Apache commons math has a RealVector interface support a mapToSelf fluid interface that works like this:
RealVector result = v.mapAddToSelf(3.4).mapToSelf(new Tan()).mapToSelf(new Power(2.3));
If I had a double[] array how would I do something similar with Java 8 streams and Java Math? The same array has to be reused.
TIA, Ole
If you already have an array and you want to modify it in place, you can use Arrays.setAll:
Arrays.setAll(arr, i -> Math.pow(Math.tan(arr[i] + 3.4), 2.3));
And just in case you don't want to modify the original array, you can create a DoubleStream from it and map each element:
double[] res =
DoubleStream.of(arr).map(d -> Math.pow(Math.tan(d + 3.4), 2.3)).toArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With