Giter VIP home page Giter VIP logo

Comments (9)

leebyron avatar leebyron commented on May 18, 2024

I can update the Readme to make it more clear that the return values are Iterators.

I'm not sure I see the value of collect() isn't iter.collect(fn) equivalent to fn(iter)?

from ecmascript-iterator-hof.

edevine avatar edevine commented on May 18, 2024

It is, but if we're dealing with several chained methods with line breaks, collect would make the code much more readable.

deepValues.values()
  .filter(value => value.isValid)
  .map(value => value.children)
  .flatten()
  .collect(Array.from);

vs

Array.from(
  deepValues.values()
    .filter(value => value.isValid)
    .map(value => value.children)
    .flatten()
);

from ecmascript-iterator-hof.

edevine avatar edevine commented on May 18, 2024

The method could also attempt to construct the callback to be used with Map and Set:

Iterator.prototype.collect = function (collect) {
  return Symbol.species in collect ? new collect[Symbol.species](this) : collect(this);
}

from ecmascript-iterator-hof.

leebyron avatar leebyron commented on May 18, 2024

I don't think all current and future uses of Species will accept that call signature

from ecmascript-iterator-hof.

RangerMauve avatar RangerMauve commented on May 18, 2024

Are there any examples in the wild that use a similarly named method?

from ecmascript-iterator-hof.

edevine avatar edevine commented on May 18, 2024

@leebyron No they won't. Neither will all functions accept the call signature either. It's up to the developer/ static type checker to know when to use them.

from ecmascript-iterator-hof.

edevine avatar edevine commented on May 18, 2024

@RangerMauve I came across the name in these meeting notes: https://github.com/rwaldron/tc39-notes/blob/master/es6/2014-11/nov-19.md#58-mapprototypemap-and-mapprototypefilter-spec--set

My suggested implementation is different, but the essence is the same: a convenient API to put iterator results back into a collection after they have been transformed.

from ecmascript-iterator-hof.

leebyron avatar leebyron commented on May 18, 2024

I'd like to keep this proposal limited to just those higher-order operations on Iterators themselves to keep a well defined scope for an eventual proposal.

I was present for that particular conversation and remember the controversy around a collect method and introducing a collection prototype. The consensus there was to start with an Iterator prototype proposal, which inspired work on this.

If work begins on some kind of shared collection prototype, then perhaps that would be the right opportunity to define a protocol for creating collections from Iterators. Right now Symbol.species might not be the complete solution.

from ecmascript-iterator-hof.

edevine avatar edevine commented on May 18, 2024

@leebyron How about a more general purpose infix method such as D3's selection.call() for chaining arbitrary functions.

class Iterator {
  call(callback, ...args) {
    return callback(this, ...args);
  }
}

from ecmascript-iterator-hof.

Related Issues (9)

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.