Fix Or Ditch Your Lib
It’s time to start the conversation about ES6 iterable data structures and functional programming. I, for one, refuse to get caught using an outdated library the first time I want to pass an iterable instead of an array.
The iterables include String, Array, Map, Set and Generator.
In addition, you can craft your own iterable using the
Since Arrays are iterable, we should rewrite our functional utilities, like
reduce, to assume an iterable
instead of an Array. I tested three simple variations on
another three on
If you want to make curried or partially applied versions, the ES6 spread operator makes it very easy:
Partial application makes use of ES6 rest parameters.
Folds and maps come to mind quickly, but you might be surprised to find your favored lib uses
while loops for variadic functions like
Combining the flexibility of these new data types with the power of functional concepts becomes so easy, you may not
even want a lib. For now, I’m running this under traceur’s runtime. But
seeing as most of the iterable data structures already appear in evergreen browsers,
for-of and spread can’t be far behind. It’s time to fix or ditch your functional lib.
- es6 5
- performance 14
- array comprehension 1
- rest operator 1
- spread operator 1
- generator comprehension 1
- for-of 1
- functional 19