function mapper(f) { return a => map(a, f); } const increment = x => x + 1; const incrementAll = mapper(increment); console.log('print:',incrementAll([1, 2, 3])); function map(iterable, f) { let iterator = iterable[Symbol.iterator](); return { // This object is both iterator and iterable [Symbol.iterator]() { return this; }, next() { let v = iterator.next(); if (v.done) { return v; } else { return { value: f(v.value) }; } } }; }