Support for binding
calebmer opened this issue · comments
This is related to #1
Can this library allow the user to do something like this:
iterable::map(identity)::forEach(console.log)
…under this proposal: https://github.com/zenparsing/es-function-bind
I envision that when the proposal gets adopted a library that does this will be needed. iterall
could be that library. As a note, RxJS already allows for this type of function application: http://reactivex.io/rxjs/manual/installation.html
Do you mean that you want to use this library's forEach
function using the function-bind syntax?
To answer concretely, currently there is no support for function-bind since the forEach
function expects an iterable/array-like as the first argument rather than using the bound-this as the expected iterable/array-like. If that proposal becomes accepted in a version of JavaScript and this becomes a requested feature, then a version of the forEach
function which supports it could be added.
If you wanted, you could use this wrapper to try it out:
import { forEach as _forEach } from 'iterall';
function forEach(fn) { return _forEach(this, fn) }
myIterable::forEach(console.log)
However I also think that function-binding support is probably not going to be a desired feature for this library since it's purpose is to provide a general purpose function for operating over any iterable/array-like - typically within other libraries - and the function-bind syntax does not provide much value for this case.
What's probably more likely is that other libraries which provide higher order functions for iterables and do support function-bind might benefit from this library's createIterator
function:
import { createIterator } from 'iterall';
import { map, filter, forEach } from 'someotherlib';
createIterator(something)::map(fn)::filter(fn)::forEach(fn)
Closing, but feel free to discuss further.
So then what's this library's unique advantage over Array.from
+ a polyfill? The low level support is already in the stdlib, what we need now is higher level functions.