Skip to content

Combinable

Combinable: object

Defined in: Core/Combinable.ts:14

all: Combinable<boolean> = allCombinable

Combines booleans with logical AND. true is the neutral element.

pipe([true, true, false], Combinable.fold(Combinable.all)); // false

any: Combinable<boolean> = anyCombinable

Combines booleans with logical OR. false is the neutral element.

pipe([false, false, true], Combinable.fold(Combinable.any)); // true

array: <A>() => Combinable<readonly A[]>

Combines arrays by concatenation. Empty array is the neutral element.

A

Combinable<readonly A[]>

pipe([[1, 2], [3], [4, 5]], Combinable.fold(Combinable.array<number>())); // [1, 2, 3, 4, 5]

fold: <A>(c) => (data) => A

Folds an array into a single value using the Combinable’s empty as the starting point.

A

Combinable<A>

(data) => A

pipe([1, 2, 3, 4, 5], Combinable.fold(Combinable.sum)); // 15
pipe([], Combinable.fold(Combinable.sum));               // 0

maybe: <A>(inner) => Combinable<Maybe<A>>

Lifts a Combinable<A> to Combinable<Maybe<A>>. None is the neutral element — combining with None on either side returns the other value unchanged. Two Some values combine their inner values using the inner Combinable.

A

Combinable<A>

Combinable<Maybe<A>>

const c = Combinable.maybe(Combinable.sum);
c.combine(Maybe.make.some(3))(Maybe.make.some(2)); // Some(5)
c.combine(Maybe.make.none())(Maybe.make.some(5));  // Some(5)

product: Combinable<number> = productCombinable

Combines numbers by multiplication. 1 is the neutral element.

pipe([2, 3, 4], Combinable.fold(Combinable.product)); // 24

string: Combinable<string> = stringCombinable

Combines strings by concatenation. Empty string is the neutral element.

pipe(["a", "b", "c"], Combinable.fold(Combinable.string)); // "abc"

struct: <R>(fields) => Combinable<R>

Derives a Combinable for a record of fields from field-level Combinable instances.

R extends Record<string, unknown>

{ [K in string | number | symbol]: Combinable<R[K]> }

Combinable<R>

const StatsCombinable = Combinable.struct({
  count: Combinable.sum,
  tags: Combinable.array<string>(),
});

sum: Combinable<number> = sumCombinable

Combines numbers by addition. 0 is the neutral element.

pipe([1, 2, 3], Combinable.fold(Combinable.sum)); // 6