Skip to content

jituanlin/pipeable-es-fns

Repository files navigation

pipeable-es-fns

A typed, curried, ES6+ functions library for pipe style programming.

Use it when

  • You like pipe style programming.
  • But Ramda is too cumbersome for you.
  • And fp-ts introduce too many FP concepts than you want.
  • You just want to use native ES6+ functions with pipe style programming.

Example

Install using Yarn by running yarn add pipeable-es-fns, or use any package manager you prefer.

And then, leverage pipe style programming with native ES functions:

import {array, object, pipe} from 'pipeable-es-fns'

const _a = pipe(
  [1, 2, 3],
  array.map((a) => [a, a] as const),
  object.fromEntries
)

const _b = pipe({a: 1, b: 2}, object.entries, object.fromEntries)

Design philosophy

  1. Just curried the ES6+ functions and try to keep others untouched.
  2. Just use the TypeScript official type definitions of ES6+ functions.
  3. Just delegate the implementation to the native ES6+ functions to avoid runtime.
  4. Unlike Ramda, the pipe function accepts data as its first argument for better type inference.
  5. Organize functions into namespace rather than function overloading for better type inference.
  6. Doesn't support deprecated methods intentionally.
  7. Encourage to specify the optional arguments explicitly.
  8. Encourage to use one function in one way only.