All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.virtdata.libbasics.shared.from_long.to_long.Flow Maven / Gradle / Ivy

There is a newer version: 2.12.15
Show newest version
package io.virtdata.libbasics.shared.from_long.to_long;

import io.virtdata.annotations.Example;

import java.util.function.LongUnaryOperator;

/**
 * Combine multiple unary operators into a single operator as
 * a higher-order function. This allows for flows to be used
 * in places where a single function is allowed.
 */
public class Flow implements LongUnaryOperator {

    private final LongUnaryOperator[] ops;

    @Example({"StringFlow(Add(3),Mul(6))","Create an integer operator which adds 3 and multiplies the result by 6"})
    public Flow(LongUnaryOperator... ops) {
        this.ops = ops;
    }

    @Override
    public long applyAsLong(long operand) {
        long value = operand;
        for (LongUnaryOperator op : ops) {
            value = op.applyAsLong(value);
        }
        return value;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy