Skip to content

Lazy

Lazy: object

Defined in: Core/Lazy.ts:16

chain: <A, B>(f) => (lazy) => Lazy<B>

Chains a Lazy-returning transformation without triggering evaluation.

A

B

(a) => Lazy<B>

(lazy) => Lazy<B>

pipe(
  Lazy.from(() => loadConfig()),
  Lazy.chain(cfg => Lazy.from(() => openConnection(cfg.dbUrl))),
);

evaluate: <A>(lazy) => A

Forces evaluation and returns the cached result. Safe to call multiple times.

A

Lazy<A>

A

const value = Lazy.evaluate(Lazy.from(() => 42)); // 42

from: <A>(f) => Lazy<A> = fromFn

Wraps a thunk in a Lazy. The thunk runs exactly once, on first evaluate.

A

() => A

Lazy<A>

const expensive = Lazy.from(() => computeExpensiveValue(input));

map: <A, B>(f) => (lazy) => Lazy<B>

Transforms the result of a Lazy without triggering evaluation.

A

B

(a) => B

(lazy) => Lazy<B>

pipe(Lazy.from(() => loadConfig()), Lazy.map(cfg => cfg.port));

tap: <A>(f) => (lazy) => Lazy<A>

Runs a side effect on the value without changing it. Fires once, on first evaluate.

A

(a) => void

(lazy) => Lazy<A>

pipe(Lazy.from(() => compute()), Lazy.tap(v => console.log("computed:", v)));