Skip to content

Logged

Logged: object

Defined in: Core/Logged.ts:29

apply: <L2, A>(arg) => <B, L1>(logged) => Logged<L2 | L1, B>

Applies a function wrapped in a Logged container to an argument wrapped in a Logged container, concatenating both logs in order.

L2 = never

A = unknown

Logged<L2, A>

<B, L1>(logged) => Logged<L2 | L1, B>

  • Logged.chain to sequence dependent computations.
  • Logged.map to transform values with a plain un-wrapped function.
const fn = Logged.make((n: number) => n * 2, ["fn-loaded"]);
const arg = Logged.make(5, ["arg-loaded"]);

const result = pipe(fn, Logged.apply(arg));
Logged.to.Pair(result); // [10, ["fn-loaded", "arg-loaded"]]

assign: <K, L2, A, B>(key, transform) => <L1>(logged) => Logged<L2 | L1, A & { [P in string]: B }>

Evaluates a new Logged computation using the current accumulator object and attaches the result to a new key.

K extends string

L2

A

B

K

(value) => Logged<L2, B>

<L1>(logged) => Logged<L2 | L1, A & { [P in string]: B }>

Logged.assignTo to initiate the accumulator object.

pipe(
  Logged.make({ a: 1 }),
  Logged.assign("b", ({ a }) => Logged.make(a + 1, ["computed b"])),
); // { value: { a: 1, b: 2 }, log: ["computed b"] }

assignTo: <K>(key) => <A, L>(logged) => Logged<L, { [P in string]: A }>

Wraps a Logged value in an accumulator record with a single specified key. Initiates the pipeline accumulator object.

K extends string

K

<A, L>(logged) => Logged<L, { [P in string]: A }>

Logged.assign to attach subsequent values to the accumulator object.

pipe(Logged.make(42), Logged.assignTo("value")); // { value: { value: 42 }, log: [] }

chain: <A, L2, B>(transform) => <L1>(logged) => Logged<L2 | L1, B> = chainLogged

Sequences two Logged computations, concatenating their logs in order. The value from the first computation is passed to transform.

A

L2

B

(value) => Logged<L2, B>

<L1>(logged) => Logged<L2 | L1, B>

  • Logged.map to transform values without appending new log entries.
  • Logged.apply to combine independent computations wrapped in Logged containers.
const result = pipe(
  Logged.make(1),
  Logged.chain(n => pipe(Logged.from.entry("step"), Logged.map(() => n + 1))),
  Logged.chain(n => pipe(Logged.from.entry("done"), Logged.map(() => n * 10))),
);

Logged.to.Pair(result); // [20, ["step", "done"]]

focus: <S, A>(lens) => <L2, B>(transform) => <L1>(logged) => Logged<L2 | L1, S>

Focuses a Logged computation on a sub-field of a data structure using a Lens, updating the focused property while accumulating any logs generated during the sub-computation.

S

A

Lens<S, A>

<L2, B>(transform) => <L1>(logged) => Logged<L2 | L1, S>

  • Lens for constructing composable property focus optics.
  • Logged.chain to sequence transformations at the root container level.
type User = { profile: { name: string } };
const profileLens = Lens.from.property<User>()("profile");
const logged = Logged.make<string, User>({ profile: { name: "alice" } });

pipe(
  logged,
  Logged.focus(profileLens)(p => Logged.make({ name: p.name.toUpperCase() }, ["capitalized name"])),
);

from: object

entry: <L>(logEntry) => Logged<L, undefined> = makeEntry

Creates a Logged container that records a single log entry and sets the value to undefined. Use this to append to the log inside a chain step.

L

L

Logged<L, undefined>

  • Logged.make to create a value with an initial log.
  • Logged.to.Pair to extract value and log at the boundary.
Logged.from.entry("operation completed"); // { value: undefined, log: ["operation completed"] }

make: <L, A>(value, log) => Logged<L, A>

Creates a Logged container with a value and an optional initial log array.

L = never

A = unknown

A

readonly L[] = []

Logged<L, A>

  • Logged.from.entry to record a single log entry without a value.
  • Logged.to.Pair to extract value and logs at the system boundary.
Logged.make(42);                  // { value: 42, log: [] }
Logged.make(42, ["initialized"]); // { value: 42, log: ["initialized"] }

map: <A, B>(transform) => <L>(logged) => Logged<L, B> = mapLogged

Transforms the value inside a Logged container while preserving accumulated logs.

A

B

(value) => B

<L>(logged) => Logged<L, B>

  • Logged.chain to sequence operations that also produce logs.
  • Logged.mapLog to transform the accumulated log entries instead.
pipe(
  Logged.make(5),
  Logged.map(n => n * 2),
); // { value: 10, log: [] }

mapLog: <L1, L2>(transform) => <A>(logged) => Logged<L2, A>

Transforms all accumulated log entries with a mapping function while preserving the value.

L1

L2

(logEntry) => L2

<A>(logged) => Logged<L2, A>

pipe(
  Logged.make(42, ["step 1", "step 2"]),
  Logged.mapLog(entry => entry.toUpperCase()),
); // { value: 42, log: ["STEP 1", "STEP 2"] }

tap: <A>(sideEffect) => <L>(logged) => Logged<L, A>

Runs a side effect on the value without modifying the value or the log.

A

(value) => void

<L>(logged) => Logged<L, A>

Logged.tapLog to inspect accumulated logs instead.

pipe(
  Logged.make(42),
  Logged.tap(n => console.log("value:", n)),
);

tapLog: <L>(sideEffect) => <A>(logged) => Logged<L, A>

Runs a side effect on the accumulated logs without modifying the value or the log.

L

(log) => void

<A>(logged) => Logged<L, A>

pipe(
  Logged.make(42, ["step 1"]),
  Logged.tapLog(entries => console.log(`Logged ${entries.length} items`)),
);

to: object

Pair: <L, A>(logged) => Pair<A, readonly L[]>

Extracts the contained value and accumulated log entries as a Pair<A, ReadonlyArray<L>>.

L

A

Logged<L, A>

Pair<A, readonly L[]>

  • Logged.make to construct a Logged container.
  • Logged.from.entry to record standalone entries.
const [value, log] = Logged.to.Pair(Logged.make(42, ["init"]));
// value = 42, log = ["init"]