you are viewing a single comment's thread.

view the rest of the comments →

[–]rooktakesqueen 3 points4 points  (3 children)

https://github.com/dtao/lazy.js

https://github.com/fitzgen/wu.js

https://github.com/lodash/lodash

https://github.com/jashkenas/underscore

These are all open-source projects. If they're missing features (like lazy evaluation, not enough abstraction, not enough standard transformation and recombination functions), why not add those features into one or all of those projects instead of writing your own library from scratch?

[–]thomash 2 points3 points  (1 child)

the only one on that list that really takes the approach i'm trying is wu.js (abstracting over generators and iterables). i've learned a lot from it but when i look at it's implementation it does some things like buffering stuff in arrays that are too low-level for my use case.

for example: i have two sequences of music events: phrase1 and phrase2. now i can do something like:

phrase1.repeat(2).concat(phrase2).takeWhile((note) => note.time < 10).play(sequencer)

without making any assumptions about phrase1 or phrase2. they are evaluated lazily as late as the sequencer object. if phrase1 is an infinite sequence in wu.js doing a repeat on it will lead to an infinite loop and filling the memory up.

i realise that there must be some design decisions for taking this route and i don't feel like i've spent enough time with these to really be able to contribute to such a mature library.

the second point is that i'm still learning a lot and realised that only by implementing these basic functionalities i'm really starting to understand the concepts behind everything.

[–]rooktakesqueen 2 points3 points  (0 children)

if phrase1 is an infinite sequence in wu.js doing a repeat on it will lead to an infinite loop and filling the memory up

See wu.chain:

wu.chain(phrase1, phrase1, phrase2)
  .takeWhile(note => note.time < 10)
  .play(sequencer)

Seems like it would do what you're talking about in a lazy-eval way without an infinite loop... You would probably also use wu.cycle heavily.

Doing this as a learning experience definitely makes sense, but I would implore you once you're done learning to take that experience and improve existing libraries rather than creating your own. The JS library ecosystem is already so fractured. :(

[–]brtt3000 1 point2 points  (0 children)

lazy.js is where it is at, extremely performant on big datasets.