Say we have a Map: let m = new Map();
, using m.values()
returns a map iterator.
But I can\'t use forEach()
or map()
o
Other answers here are... Weird. They seem to be re-implementing parts of the iteration protocol. You can just do this:
function* mapIter(iterable, callback) {
for (let x of iterable) {
yield callback(x);
}
}
and if you want a concrete result just use the spread operator ...
.
[...iterMap([1, 2, 3], x => x**2)]