traverse
import { traverse } from "https://github.gh-proxy.cn/raw.githubusercontent.com/baetheus/fun/main/record.ts";Traverse a ReadonlyRecord, mapping each A into an algebraic data type V (so V), then collecting each I in V back into a ReadonlyRecord, ultimately returning V<ReadonlyRecord>. In more concrete terms this can take ReadonlyRecord<Option> and return Option<ReadonlyRecord> (or any other inner type.
Traverse, in general, is much like reducing and collecting over the outer and inner types of an ADT at the same time.
@example
import * as R from "./record.ts";
import * as O from "./option.ts";
import { pipe } from "./fn.ts";
const traverseOption = R.traverse(O.ApplicableOption);
const swapOption = traverseOption((o: O.Option<number>) => o);
const result1 = swapOption({ one: O.some(1), two: O.some(2) });
// Some({ one: 1, two: 2 });
const result2 = swapOption({ one: O.some(1), two: O.none }); // None
TODO: Revisit because mutability needs proof
function traverse<V extends Kind>(A: Applicable<V>): <A, I, J = never, K = never, L = unknown, M = unknown>(favi: (value: A, key: string) => $<V, [I, J, K], [L], [M]>) => (ua: ReadonlyRecord<A>) => $<V, [ReadonlyRecord<I>, J, K], [L], [M]>;
§
traverse<V extends Kind>(A: Applicable<V>): <A, I, J = never, K = never, L = unknown, M = unknown>(favi: (value: A, key: string) => $<V, [I, J, K], [L], [M]>) => (ua: ReadonlyRecord<A>) => $<V, [ReadonlyRecord<I>, J, K], [L], [M]>
[src]§Parameters
§
A: Applicable<V>
[src]§Return Type
§
<A, I, J = never, K = never, L = unknown, M = unknown>(favi: (value: A, key: string) => $<V, [I, J, K], [L], [M]>) => (ua: ReadonlyRecord<A>) => $<V, [ReadonlyRecord<I>, J, K], [L], [M]>
[src]