you are viewing a single comment's thread
view the rest of the comments
[–] 6 points 6 months ago* (last edited 6 months ago) (3 children)

Only tangentially related, but I dislike that filter and map are eager in JS. Meaning if you chain them, you allocate N-1 arrays that are being discarded right away. C#, Java and Rust have the right approach.

  • source
  • hideshow 3 child comments
  • [–] 3 points 6 months ago (2 children)

    Are they eager even with generators?

  • source
  • parent
  • hideshow 2 child comments
  • [–] 6 points 6 months ago (1 child)

    You made me go down the rabbit hole with that question. TIL the very same methods exist on Iterator's prototype. They aren't eager, no.

    You can get an iterator out of an array with Array.prototype[Symbol.iterator]() and you can collect an iterator into an array with Iterator.prototype.toArray().

  • source
  • parent
  • hideshow 1 child comment
  • [–] 2 points 6 months ago

    One reason you may not have known this is that these (iterator methods, not the Iterator itself) are newish additions to Javascript and only available in all the big browsers for just over 1 year.

  • source
  • parent