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

hydra.lib.sets.Remove Maven / Gradle / Ivy

package hydra.lib.sets;

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

import java.util.List;
import java.util.function.Function;
import java.util.HashSet;
import java.util.Set;

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


public class Remove extends PrimitiveFunction {
    public Name name() {
        return new Name("hydra/lib/sets.remove");
    }

    @Override
    public Type type() {
        return lambda("x", function("x", set("x")));
    }

    @Override
    protected Function>, Flow, Term>> implementation() {
        return args -> Flows.map(Expect.set(Flows::pure, args.get(1)), arg -> Terms.set(apply(args.get(0), arg)));
    }

    public static  Function, Set> apply(X elem) {
        return (arg) -> apply(elem, arg);
    }

    /**
     * Apply the function to both arguments.
     */
    public static  Set apply(X elem, Set arg) {
        Set newSet = new HashSet<>(arg);
        newSet.remove(elem);
        return newSet;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy