Skip to content

compose

compose<A, B, C>(bc): (ab) => Refinement<A, C>

Defined in: Core/Refinement.ts:70

Chains two refinements: if ab narrows A to B and bc narrows B to C, the result narrows A directly to C.

Data-last — the first refinement ab is the data being piped.

A

B

C

Refinement<B, C>

(ab): Refinement<A, C>

Refinement<A, B>

Refinement<A, C>

type NonEmptyString = string & { readonly _tag: "NonEmpty" };
type TrimmedString  = NonEmptyString & { readonly _tag: "Trimmed" };

const isNonEmpty: Refinement<string, NonEmptyString> =
  Refinement.make(s => s.length > 0);
const isTrimmed: Refinement<NonEmptyString, TrimmedString> =
  Refinement.make(s => s === s.trim());

const isNonEmptyTrimmed: Refinement<string, TrimmedString> = pipe(
  isNonEmpty,
  Refinement.compose(isTrimmed)
);