David, I like the way you paint your bike sheds. Array.range() (or similarly
functional but differently named) is definitely another one of those
"oft-rerolled" solutions.

Rick

On Sun, Jul 10, 2011 at 4:23 PM, David Herman <[email protected]> wrote:

> > So from this viewpoint (and regarding that example with squares), it's
> good to have also `Array.seq(from, to)` method (the name is taken from
> Erlang, I just frequently uses lists:seq(from, to) there):
>
> <bikeshed>Array.range seems like an intuitive name as well.</bikeshed>
>
> > Array.seq(1, 5).map((x) -> x * x); [1, 4, 9, 16, 25]
>
> This pattern (integer range immediately followed by map) is so common that
> many Schemes have a more general function that fuses the two traversals,
> sometimes called build-list or list-tabulate:
>
>    Array.build(n, f) ~~~ [f(0), ..., f(n-1)]
>
> Another common and useful fusion of two traversals that's in many Schemes
> is map-filter or filter-map:
>
>    a.filterMap(f) ~~~ [res for [i,x] of items(a) let (res = f(x, i)) if
> (res !== void 0)]
>
> I rather arbitrarily chose to accept both null and undefined here as way to
> say "no element" -- a reasonable alternative would be to accept *only*
> undefined as "no element".
>
> Dave
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to