4 ms·
Neat, but I think that functions already do what we need. For one thing, the example isn't the most compelling, because you can: const greeting = 'hello'.
by MathMonkeyMan 1y ago
Neat, but I think that functions already do what we need.
For one thing, the example isn't the most compelling, because you can:
const greeting = 'hello'.toUpperCase() + '!!!';
or
const greeting = 'HELLO!!!';
That said, there is already:
function thrush(initial, ...funcs) {
return funcs.reduce(
(current, func) => func(current),
initial);
}
const greeting = thrush('hello', s => s.toUpperCase(), s => s + '!!!');
- nonethewiser 1y agoAre any of the cases compelling? Thinking of the actual proposal. It creates some new magic with |> and % just for syntactic sugar.
- accrual 1y agoI am all for clean syntax but I feel like JS has already reached a nice middle ground between expressiveness (especially w/ map/reduce/filter) and readability. I'd personally rather not have another syntax that everyone will have to learn unless we're already moving to a new language.
- nonethewiser 1y agoI agree but to steelman it, what about custom functions? I think just doing it naively is perfectly fine. Or if you want use some pipe utility. Or wrap the array, string, etc. with your own custom methods.
- IshKebab 1y agoI think JS's map/reduce/filter design is one of the worst ones out there actually - map has footguns with its extra arguments and everything gets converted to an array at the drop of a hat. Still, pipeline syntax probably won't help fix any of that.
- eyelidlessness 1y ago> everything gets converted to an array at the drop of a hat Can you name an example? IME the opposite is a more common complaint: needing to explicitly convert values to arrays from many common APIs which return eg iterables/iterators.
- IshKebab 1y ago`map` returns an array and can only be called on an array.
- eyelidlessness 1y agoRight, but I’m not clear on what gets converted to an array. Do you mean more or less what I said in my previous comment? That it requires you (your code, or calling code in general) to perform that conversion excessively?
- recursive 1y agoPeople write a lot of stuff like [...iterable].map(fn). They do it so much it's as if they do it each time a hat drops.
- eyelidlessness 1y agoThank you for clarifying. (I think?) I think what confused me is the passive language: "everything gets converted" sounds (to me) like the runtime or some aspect of language semantics is converting everything, rather than developers. Whereas this is the same complaint I mentioned.
- Timwi 1y agoOne gripe I have is that the result of map/filter is always an array. As a result, doing `foo.map(...).filter(...).slice(0, 3)` will run the map and the filter on the entire array even if it has hundreds of entries and I only need the first 10 to find the 3 that match the filter.
- rco8786 1y agoWhatever that thrush thing is feels 10x more gross than the pipe
- svieira 1y agoThrush is the "T combinator" - I believe that the "Thrush" name comes from To Mock a Mockingbird by Raymond Smullyan [1]. [1]: https://www.amazon.com/Mock-Mockingbird-Other-Logic-Puzzles/dp/0192801422 https://www.amazon.com/Mock-Mockingbird-Other-Logic-Puzzles/... [2]: https://en.wikipedia.org/wiki/Combinatory_logic#In_computing https://en.wikipedia.org/wiki/Combinatory_logic#In_computing [3]: https://leanpub.com/combinators/read#leanpub-auto-the-thrush https://leanpub.com/combinators/read#leanpub-auto-the-thrush
- flexagoon 1y agoNot if you consider that the linked repo requires you to use asPipe on all functions first. So it's this: const greeting = thrush( 'hello', s => s.toUpperCase(), s => s + '!!!' ); Vs this: const upper = asPipe(s => s.toUpperCase()) const ex = asPipe((s) => s + '!!!') const greeting = pipe('hello') | upper | ex await greeting.run() (And that doesn't work in reality, as the top comment here notes)