Skip to content

Can iterators be pretty and immutable? #504

Closed
@tomek-he-him

Description

@tomek-he-him

I hope to start a discussion about 11.1.

I bet you know trine. The whole concept of the lib is based on iterators – to have a unified set of functions working with any sort of collection. It looks very elegant and “native” to JS:

const characters = strings
    ::map(String.prototype.split::partial(""))
    ::reduce(Array.prototype.concat)
    .sort()
    ::uniq();

👍 Using iterators this way doesn’t involve managing state, except when writing the utilies.

👍 There’s no risk of mutating stuff. Every function is returns a new iterator.

👍 One more bonus – the thing is lazy. So you can map over infinite collections, etc. Lots of functional programming goodness.

👎 There’s one “but”. Working with iterators in such an elegant way is only possible with the function bind syntax. And that doesn’t come into the spec until ES 2016 (if at all). They do transpile cleanly to ES5 with babel though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions