|
|
|
|
|
by thaumasiotes
1921 days ago
|
|
A forEach can easily return a transformed list of values. acc = []
for el in values:
acc.append(f(el))
return acc
This hierarchy doesn't exist; you can pretty much implement any of them in terms of the others.To make that untrue, you need to define very strict limits on what else your language can do. (Sure, we produce a transformed list here through the use of side effects. But note that the original example sparking the claim that forEach can't do what map can was this: .forEach(() => button.click())
Side effects are clearly allowed.) |
|
You can implement any of them in terms of the others, but only if you break convention and introduce side effects. Follow convention and try to implement (for example) reduce with map and you'll find that it's not possible.