Callbag Pipe Utility

1.2.0 · active · verified Sun Apr 19

callbag-pipe is a lightweight utility function designed to chain callbags together in a functional pipeline, conceptually similar to `Ramda.pipe` or `lodash.flow`. It serves as a foundational component within the Callbag ecosystem, facilitating the clear and concise composition of Callbag sources and operators. The current stable version is 1.2.0, and as a small, focused utility, it typically sees a low-frequency release cadence, with updates primarily for compatibility or minor enhancements rather than new features. Its key differentiator is its seamless integration with the Callbag specification, making it a natural choice for creating and consuming Callbag streams, while offering a familiar functional composition pattern. It provides TypeScript types for improved developer experience and type safety.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates creating a complete Callbag stream from source to sink using `pipe`, combining two interval streams, mapping their values, taking a limited number, and logging the output.

import { pipe } from 'callbag-pipe';
import interval from 'callbag-interval';
import forEach from 'callbag-for-each';
import combine from 'callbag-combine';
import take from 'callbag-take';
import map from 'callbag-map';

// Create a pipeline that combines two intervals, maps their values, takes the first 10, and logs them.
pipe(
  combine(interval(100), interval(350)),
  map(([x, y]: [number, number]) => `X${x},Y${y}`),
  take(10),
  forEach((x: string) => console.log(x))
);

// Expected output:
// X2,Y0
// X3,Y0
// X4,Y0
// X5,Y0
// X6,Y0
// X6,Y1
// X7,Y1
// X8,Y1
// X9,Y1
// X9,Y2

view raw JSON →