0.0.3 • Published 5 years ago

pline v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

pline - pipelining for TS/JS

Example

import { pipe, pipeline } from 'pline'

function flatMap<T, U>(f: (x: T) => Array<U>): (array: Array<T>) => Array<U> {
  return (array: Array<T>) => {
    let result = []
    array.forEach(x => {
      result = [...result, ...f(x)]
    })
    return result
  }
}

function map<T, U>(f: (x: T) => U): (array: Array<T>) => Array<U> {
  return (array: Array<T>) => array.map(f)
}

const result = [1, 2, 3][pipe](
  flatMap(x => [x, x * 10]),
  map(x => `${x}`)
) // ["1", "10", "2", "20", "3", "30"]


// also
const func = pipeline(
  flatMap(x => [x, x * 10]), 
  map(x => `${x}`)
)
const result = func([1, 2, 3])

Features

How to install

$ npm install pline
// yarn add pline

Documentation

pipe

chain functions

pipeline

compose functions