GithubHelp home page GithubHelp logo

ecmascript-iterator-hof's People

Contributors

leebyron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Forkers

smartb2b

ecmascript-iterator-hof's Issues

Should transforms operate on "completion value"?

The new for ... of syntax ignores the completion value, so it would make sense to ignore it for the different functions introduced here.

function *example(){
 yield 1;
 yield 2;
 return 3;
}

for(let i of example()) console.log(i);

Outputs

1
2

Is flatMap really necessary?

On can achieve the exact same effect by chaining map and flatten. When xstream (an Observable implementation) was being made, the creator, @staltz, omitted "flatMap" because [it was easier to understand]. I think this reasoning applies to higher order functions with Iterators.

Add collect method

Consider this snippet in the readme which incorrectly suggests the return value of flatten is an array.

var deepValues = [ [ 'A' ], [[ 'B' ]], 'C' ]
var flat = deepValues.values().flatten() // [ 'A', ['B'], 'C' ]

Adding the method collect:

class Iterator<T> {
    collect<R>(fn: (iterator: Iterator<T>) => R): R;
}

Would allow:

var deepValues = [ [ 'A' ], [[ 'B' ]], 'C' ]
var flat = deepValues.values().flatten().collect(Array.from) // [ 'A', ['B'], 'C' ]

Bind operator for chaining

Once you introduce a series of operators, people are bound to want to have more.
I think it would be a good idea to introduce a .bind(fn, ...args) operator which would allow chaining with custom operators without having to subclass or modify the prototype.

Async Iterators

Would it make sense for this proposal to also define the same functions for Async Iterables to kill two birds with one stone?

Having higher order functions on async iterables would make async programming extremely powerful.

Spec functions as generators

Is this an opportunity to spec the functions as generators? A few examples:

class Iterator {
    *concat(...iterators) {
        yield* this;
        for (iterator in iterators) {
            yield* iterator;
        }
    }

    *map(mapFn) {
        for (value in this) {
            yield mapFn(value);
        }
    }

    *filter(filterFn) {
        for (value in this) {
            if (filterFn(value)) {
                yield value;
            }
        }
    }

    *flatten() {
        for (iterator in this) {
            yield* iterator;
        }
    }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.