T - the argument type of the operationpublic interface Op<T> extends Function<T[],T>, Supplier<Op<T>>
T[] -> T.
final Op<Double> add = Op.of("add", 2, v -> v[0] + v[1]);
final Op<Double> add3 = Op.of("add3", 3, v -> v[0] + v[1] + v[2]);
final Op<Double> sub = Op.of("sub", 2, v -> v[0] - v[1]);
final Op<Double> sin = Op.of("sin", 1, v -> Math.sin(v[0]));Op interface are usually immutable and doesn't
maintain internal state. But some instance are ephemeral with changing state.
This classes must override the get() method inherited from the
Supplier interface and return a new instance.Var,
Const,
EphemeralConst| Modifier and Type | Method and Description |
|---|---|
int |
arity()
Return the arity of the operation function.
|
default Op<T> |
get()
Return
this operation, or a new instance from the same type, if
the operation needs to maintain internal state. |
default boolean |
isTerminal()
Determines if the operation is a terminal operation.
|
String |
name()
Return the name of the operation.
|
static <T> Op<T> |
of(String name,
int arity,
Function<T[],T> function)
Create a new operation from the given parameter.
|
int arity()
default boolean isTerminal()
true if the operation is a terminal operation,
false otherwisedefault Op<T> get()
this operation, or a new instance from the same type, if
the operation needs to maintain internal state. This is essentially the
case for ephemeral constants.get in interface Supplier<Op<T>>this operation, or a new instanceEphemeralConststatic <T> Op<T> of(String name, int arity, Function<T[],T> function)
T - the operation typename - the operation namearity - the arity of the operationfunction - the function executed by the operation. In order to work
properly, the given function should be stateless and must not have
side effects.NullPointerException - if the given name or function
is nullIllegalArgumentException - if the given arity is smaller
than zero© 2007-2017 Franz Wilhelmstötter (2017-08-22 19:30)