Skip to content

Instantly share code, notes, and snippets.

@tabatkins
Last active March 24, 2021 16:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save tabatkins/799ac7700bc42698b309654d1d9a4699 to your computer and use it in GitHub Desktop.
Pipeline notes

Real world use-case: someone asking for Object.values()/etc to be installed as Symbol-keyed properties on Object.prototype, so they can have method chains working on arrays/iterators that produce an Object at some intermediate point, without having to go back and wrap an entire chunk of the method chain in a big wrapping Object.values().

That is, they're prefer not to have to write this code:

const x = Object.values(array.filter(x=>x).map(x=>f(x)).reduce(intoObjectSomehow)).map(y=>g(y))

which requires going back to the beginning of the method chain to add the Object.values( prefix, and when reading requires you to carefully track parens to know when the closing ) appears.

Instead, they're asking to be able to write:

const x = array.filter(x=>x).map(x=>f(x)).reduce(intoObjectSomehow)[Symbol.objectValues]().map(y=>g(y))

We can't do this for several reasons, but pipeline would have solved their problem automatically:

const x = array.filter(x=>x).map(x=>f(x)).reduce(intoObjectSomehow) |> Object.values(#).map(y=>g(y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment