This file implements frozen values in Javascript. In a Typescript-like manner :

type Lazy<A> = Frozen<A> | Evaluated<A>
type Frozen<A> = { func: () => A }
type Evaluated<A> = { func: () => A, result: A }

Note that this implementation contains side-effects when thawing values, but preserves the invariant that the computed value is always the same.

import * as L from "./src/utils/lazy.js";

const aVal = L.freeze(() => 3 + 5); // builds a frozen value
anyToString(aVal); // -> <Frozen>
L.thaw(aVal); // computes the frozen value
anyToString(aVal); // -> <Evaluated(8)>
anyToString(L.value(aVal)); // -> 8

Index

Functions