jussi-kalliokoski / trine

A utility library for modern JavaScript.
ISC License
1.42k stars 35 forks source link

Pass items to transformer in `iterable/map`. #45

Closed kasperisager closed 9 years ago

kasperisager commented 9 years ago

This allows the use of ES6 lambdas in iterable/map rather than relying solely on function binding.

This...

[1, 2, 3]::map(function () { return this * 2 })

...can therefore be shortened to:

[1, 2, 3]::map(x => x * 2)
kasperisager commented 9 years ago

Note: This may have implications for partially applied functions.

jussi-kalliokoski commented 9 years ago

Hmm, this feels a bit like magic to me. :/ I'd prefer introducing explicit function/shiftThis for this use case, e.g.

import { shiftThis as _ } from "trine/function/shiftThis";
import { map } from "trine/iterable/map";

[1, 2, 3]::map(_(x => x * 2))
nikhedonia commented 9 years ago

@jussi-kalliokoski: i think your proposal is the way to go