Hyperse Pipeline

Monad Integration

Compose Either, Maybe and Validation values directly inside a pipe.

The reactive pipeline detects monadic return values and composes them automatically — you do not need to unwrap a step's result before the next step receives it.

Supported libraries:

LibraryTypes
monetEither, Maybe, Validation
fp-tsEither
purify-tsEither, EitherAsync, Maybe, MaybeAsync

Two-argument steps

When a step produces a monad, the next step receives two arguments: the right/bound value, and the left value. In the examples below n is the bound value and l holds the left side.

Either

import { pipe } from '@hyperse/pipeline';
import { Either } from 'monet';

const result = await pipe(
  () => Either.left(123),
  (n, l) => l + 1 // `l` contains the left value
)();
// result => 124

Maybe

import { pipe } from '@hyperse/pipeline';
import { Maybe } from 'monet';

const result = await pipe(
  () => Maybe.Some(123),
  (n) => n + 1
)();
// result => 124

Purify-ts

import { pipe } from '@hyperse/pipeline';
import { Either } from 'purify-ts';

const result = await pipe(
  () => Either.Left(123),
  (n, l) => l + 1
)();
// result => 124

Async monads are supported too

EitherAsync and MaybeAsync from purify-ts are recognised alongside their synchronous counterparts — no extra configuration required.

Combining with early exit

Monads and exitPipe compose. A monadic step can still short-circuit the whole pipeline:

import { pipe, exitPipe, isExitPipeValue } from '@hyperse/pipeline';
import { Either } from 'monet';

const result = await pipe(
  () => Either.right(123),
  (n) => (n > 100 ? exitPipe(n) : n + 1),
  () => 'unreachable'
)();

if (isExitPipeValue(result)) {
  console.log(result.r); // 123
}

Next steps

On this page