This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This class wraps an iterator/iterable and allows the map/filter/reduce methods | |
* to be used without being forced to make intermediate temporary arrays. | |
* I've also implemented the flatten and flatmap functions for convenience | |
*/ | |
class FunctionalIterator { | |
constructor(source) { | |
// Get iterator from source, if present. Otherwise, assume that the source is an iterator | |
this.source = source[Symbol.iterator] ? source[Symbol.iterator]() : source; | |
} |