Skip to content

Implementation of `pipe` and `compose` using types from at 'pipe-and-compose-types.

Notifications You must be signed in to change notification settings

babakness/pipe-and-compose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Introduction

This exposes a pipe, compose and pipeline function. It implements the function types from pipe-and-compose-types. The benefits of this is:

  • parameter name preservation
  • theoritically unlimited functions can be composed (recursive)
  • variadic input for both Pipe and Compose
  • friendly messages on error, pointing to the problem

preserves parameter names

provides helpful errors

See tests for more examples

Installation

npm install pipe-and-compose

Usage

Parameter names perserved

const longerWord = ( word1: string, word2: string ) => word1.length > word2.length ? word1 : word2
const longestWord = ( word: string, ...words: string[]) => [word,...words].reduce(longerWord, '')
const length = ( xs: string | unknown[] ) => xs.length
const PIPE_longestWordLength = pipe(
  longestWord,
  length,
) // ( word: string, ...words: string[] ) => number

Works with compose as well

const PIPE_longestWordLength = compose(
  length,
  longestWord,
) // ( word1: string, word2: string ) => number

Read more at https://dev.to/babak/introducing-the-recursive-pipe-and-compose-types-3g9o

About

Implementation of `pipe` and `compose` using types from at 'pipe-and-compose-types.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published