Skip to content

Latest commit

 

History

History
32 lines (22 loc) · 1.33 KB

NOTES.md

File metadata and controls

32 lines (22 loc) · 1.33 KB

pipe vs compose

For some reason I've thought I needed a function for doing function composition. My real intention was to use something to pipe results from one computation to another as composition passes the value from right to left.

This article about Pipe Function in JavaScript has provided help in remembering what I wanted to achieve.

In fact I have seen this many times before in staltz/callbag-pipe and RxJS.

API considerations

To enable the option to compose pipelines out of smaller parts with async code, all functional helpers would need to be able to work with Promises.

const fetchUser = id =>
  fetch('/user/' + id)
    .then(res => res.json())

const fn = pipe(
  fromPromise(fetchUser),
  map(x => x + 1),
  withDefault(10)
)

const id = await fn(10023)

AST Analysis