Hacker News new | ask | show | jobs
by aabbcc1241 1414 days ago
An easier alternative is to wrap the value into an array, then use `.map()` for each function in the chain, and finally escape the value with `[0]`

I made a similar data structure[1] to allow adding side effect (no return value) as part of the chained function.

[1] https://github.com/beenotung/tslib/blob/9f9a9274c1e13be7ba83...

3 comments

If you extract this `Chain` class to a separate package, I would gladly reuse it in my applications. I've been thinking about creating a `Vavr`[0] clone in typescript, as I really like the syntax used in that library, especially the `Try` construct.

[0] https://www.vavr.io/

This works great for small datasets, but often you’ll have to eventually use streams rather than arrays. I’ve used pull-stream to do this in the past.
.use is a nice quality of life feature!