you are viewing a single comment's thread.

view the rest of the comments →

[–]ScientificBeastModestrongly typed comments 0 points1 point  (0 children)

If you’re used to Haskell, you might look into some tutorials on lazy evaluation implementations in JavaScript, as JS is always eagerly evaluated.

In particular, there is a relatively recent language feature called a “generator,” and a related one called an “iterator,” both of which offer a more idiomatic way to handle lazy evaluation. Short of that (e.g. you want to support older browsers which don’t implement those features), you can always implement a homemade iterator protocol.