pline
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i pline

Weekly Downloads

1

Version

0.0.3

License

MIT

Unpacked Size

5.43 kB

Total Files

7

Last publish

Collaborators

  • tosuke