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))