@FunctionalInterface
public interface VarDoubleOperator
Although this basically works for a variable double array
via the apply(double...)
method implementors
have to implement the method apply(DoubleIndexable)
with a DoubleIndexable
argument. This is done
to make this class generally more useful without the need
to copy arrays.
An example using the maxOp
operator defined in
the documentation of fromBinary(DoubleBinaryOperator, double)
should illustrate this (with Point2D
arguments):
double maxX = maxOp.apply(DoubleIndexable.viewArray(Point2D::getX, p1, p2, p3, p4));
Modifier and Type | Method and Description |
---|---|
default double |
apply(double... values)
Apply this operator.
|
double |
apply(DoubleIndexable values)
Apply this operator.
|
static VarDoubleOperator |
fromBinary(java.util.function.DoubleBinaryOperator binaryOp,
double startValue)
Create an variable args operator from applying a binary operator
over and over.
|
default double apply(double... values)
apply(DoubleIndexable)
.values
- arguments on which this operator is applieddouble apply(@NotNull DoubleIndexable values)
values
- indexable providing the values on which this operator operates@NotNull static VarDoubleOperator fromBinary(@NotNull java.util.function.DoubleBinaryOperator binaryOp, double startValue)
Eg
On each application the currently accumulated result becomes the left (first) argument ofVarDoubleOperator maxOp = VarDoubleOperator.fromBinary(Math::max, Double.NEGATIVE_INFINITY); double max = maxOp.apply(1, -7, Math.PI, Math.atan(17));
binaryOp
, while the run value becomes the right (second).binaryOp
- binary operatorstartValue
- start value (result of operator if no values are given)