Follow

Having used Collections and transducers and slices—all high-performance and high-expressivity array operators—I find 's primitives that casually create arrays at every step in a transformation chain infelicitous.

Object.entries, Object.assign, Array.map… I'm creating and destroying arrays left and right, which throw a lot of performance on the floor. The perf-conscious alternative is not very expressive: to write nested for-loops.

fitzgen.github.io/wu.js/

Wu billed as " for iterables".

And ZOMFG!

`require('wu').tang.clan` returns 36 🙌 hip-hop Easter eggs in code libraries for the win!!!

@22 JS returns iterators for a lot of things these days but yeah, generally true

@charlag Aha, you're right, my performant for-loops all use iterators! I wonder, we should be able to port one of these streams libraries to JS iterators right? And it will probably be quite fully-featured?

🤔!

@22 which stream libraries?
There are async iterators planned afaik

@charlag I've used it relatively little but I do like the Java collections + streams APIs, in part because they support quite clever "sinks", i.e., ways of converting streams (JS iterators) back to data types including arrays, sets, and maps.

@22 I wouldn't say it's unique to Java, they rather copied it and it's not super easy to extend (by design - they want to optimize it).
As I said, lodash is there, Ramda is there, fantasy-land and many others are there

@charlag I'll look again at Lodash, Ramda, etc., now that I have a clearer grasp of my pain points (thanks to your nudges!), because…

Yeah, Lodash doesn't consume iterators:

_.flatMap([1,2,3].values(), x=>[x+1, x+2]) // returns []

I'll check the others.

I'm ok with the Java API constraining itself for performance. But it'll be good to check the JS libs' APIs to see how ergonomic they are, and then see if we can add performant iterator support.

@22 I like how Rust does this a lot. And it's super performant, up to SIMD, unrolling and stuff.

@22 if really seems like none of them is doing it really and it's... weird. Maybe there are reasons but I guess not.

Sign in to participate in the conversation
Octodon

Octodon is a nice general purpose instance. more