Introduction, comprehensions beyond arrays
brendan at mozilla.com
Fri May 10 12:59:20 PDT 2013
Apologies again, I'm a beat or three behind today. I think you gave the
expr2(x).flatMap(y => ...
exprN(x, y, ...).map(z =>
result(x, y, ..., z)
Nice when Scala and JS look alike!
I don't think we'd make comprehensions return a monad, specifically a
Promise, even if we had the silly things (Promises, I mean -- just
teasing about monads) in the language.
JS is eager and mutational. Although Mark and I have discussed privately
trying to get E-like "featureless" promises, which become their
fulfillment value, we think it's too big a stretch. Especially in light
of existing libraries, but even starting fresh.
Without E-like featureless/"becoming" promises, I wouldn't foist them on
syntax for eager computations such as comprehensions and generator
So is the explicit functional style, with arrows for sugar, really too much?
Brendan Eich wrote:
> Brendan Eich wrote:
>> Mike Stay wrote:
>>> On Fri, May 10, 2013 at 1:07 PM, Brendan Eich<brendan at mozilla.com>
>>>> What's wrong with the iteration protocol?
>>> Nothing at all for arrays. For every other monad, there's no sugar:
>>> the only monad multiplication that's supported is list concatenation.
>> Iteration is much more general than "arrays".
> Oh, sorry -- you mean comprehensions (not the iteration protocol,
> which is used by all for-of syntax) are only about creating fresh arrays.
> Yes, that's true. One alternative is a generator expression, which
> doesn't build any eager data structure, rather iterates and yields
> values on demand.
> As Jason pointed out, arrows sweeten the explicit monadic patterns,
> e.g. monadic Promises. To close this thread it would be helpful to see
> an example where you use all the ES6 sugar, and then say why you'd
> still want another special form.
> es-discuss mailing list
> es-discuss at mozilla.org
More information about the es-discuss