Let’s say I had the following code:
let array = [1, 2, 3] array.forEach(x => someFunc(x))
In Java, I know the second line could be simpler using
Streams (at least for static methods), like so:
Essentially I’m asking is there an analog for the
x => someFunc(x)?
In the simplest case, you can replace
array.forEach(x => someFunc(x))
but there’s some fine print you should be aware of:
this generally doesn’t work with object methods:
the callback should accept exactly one argument or conform to the
callback(element, index, this). For example,
array.map(parseInt)won’t work either, because
parseInthas its own idea of what the second argument means.