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

hydra.lib.lists.Pure Maven / Gradle / Ivy

package hydra.lib.lists;

import hydra.Flows;
import hydra.compute.Flow;
import hydra.core.Name;
import hydra.core.Term;
import hydra.core.Type;
import hydra.dsl.Terms;
import hydra.graph.Graph;
import hydra.tools.PrimitiveFunction;

import java.util.List;
import java.util.Collections;
import java.util.function.Function;

import static hydra.dsl.Types.function;
import static hydra.dsl.Types.lambda;
import static hydra.dsl.Types.list;


public class Pure extends PrimitiveFunction {
    public Name name() {
        return new Name("hydra/lib/lists.pure");
    }

    @Override
    public Type type() {
        return lambda("a", function("a", list("a")));
    }

    @Override
    protected Function>, Flow, Term>> implementation() {
        return args -> Flows.pure(Terms.list(apply(args.get(0))));
    }

    /**
     * Apply the function to the single argument.
     */
    public static  List apply(X single) {
        return Collections.singletonList(single);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy