News for hackers. Stuff that matters.
Re:Click by thaumasiotes on Saturday March 20, 2021 @02:31AM (#26521229)
> You can implement any of them in terms of the others, but only if you break convention and introduce side effects.

This can't be right. forEach has no effects other than side effects. A convention that says not to use side effects prevents you from using forEach at all.

But that would make claims about the place of forEach in a hierarchy into meaningless nonsense.

> The forEach isn't returning it in your example, the line after it is returning.

That depends on your point of view. C has numerous functions which accept pointer parameters and return values in those parameters. That's just the normal way to return multiple values in C.

And by that standard, the forEach itself is returning the transformed list; that's where the transformation occurs. The following `return` line is only necessary if this is a snippet within a function whose purpose is to execute a for statement; you would actually do this inline, by just writing the for statement without needing a following `return`.

Re:Click by HeavyStorm on Saturday March 20, 2021 @05:32AM (#26521846)
I really don't think you got the original point...
Re:Click by thaumasiotes on Saturday March 20, 2021 @12:28PM (#26524194)
What was the original point?
Re:Click by lurn on Saturday March 20, 2021 @01:10PM (#26524471)
I think they’re only talking about JavaScript, in which case the forEach function doesn’t return anything. So you can do x.map(…).forEach(…) because map returns an array. But u can’t do x.forEach(…).map(…) Ur examples seem like they’re for a different language.