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

fj.F2W Maven / Gradle / Ivy

Go to download

Functional Java is an open source library that supports closures for the Java programming language

There is a newer version: 5.0
Show newest version
package fj;

import fj.control.parallel.Promise;
import fj.data.*;

/**
 * Created by MarkPerry on 22/01/2015.
 */
public abstract class F2W implements F2 {

    /**
     * Partial application.
     *
     * @param a The A to which to apply this function.
     * @return The function partially applied to the given argument.
     */
    public final F1W f(final A a) {
        return F1W.lift(F2Functions.f(this, a));
    }

    /**
     * Curries this wrapped function to a wrapped function of arity-1 that returns another wrapped function.
     *
     * @return a wrapped function of arity-1 that returns another wrapped function.
     */
    public final F1W> curry() {
        return F1W.lift(F2Functions.curry(this));
    }

    /**
     * Flips the arguments of this function.
     *
     * @return A new function with the arguments of this function flipped.
     */
    public final F2W flip() {
        return lift(F2Functions.flip(this));
    }

    /**
     * Uncurries this function to a function on tuples.
     *
     * @return A new function that calls this function with the elements of a given tuple.
     */
    public final F1W, C> tuple() {
        return F1W.lift(F2Functions.tuple(this));
    }

    /**
     * Promotes this function to a function on Arrays.
     *
     * @return This function promoted to transform Arrays.
     */
    public final F2W, Array, Array> arrayM() {
        return lift(F2Functions.arrayM(this));
    }

    /**
     * Promotes this function to a function on Promises.
     *
     * @return This function promoted to transform Promises.
     */
    public final F2W, Promise, Promise> promiseM() {
        return lift(F2Functions.promiseM(this));
    }

    /**
     * Promotes this function to a function on Iterables.
     *
     * @return This function promoted to transform Iterables.
     */
    public final F2W, Iterable, IterableW> iterableM() {
        return lift(F2Functions.iterableM(this));
    }

    /**
     * Promotes this function to a function on Lists.
     *
     * @return This function promoted to transform Lists.
     */
    public final F2W, List, List> listM() {
        return lift(F2Functions.listM(this));
    }

    /**
     * Promotes this function to a function on non-empty lists.
     *
     * @return This function promoted to transform non-empty lists.
     */
    public final F2W, NonEmptyList, NonEmptyList> nelM() {
        return lift(F2Functions.nelM(this));
    }

    /**
     * Promotes this function to a function on Options.
     *
     * @return This function promoted to transform Options.
     */
    public final F2W, Option, Option> optionM() {
        return lift(F2Functions.optionM(this));
    }

    /**
     * Promotes this function to a function on Sets.
     *
     * @param o An ordering for the result of the promoted function.
     * @return This function promoted to transform Sets.
     */
    public final F2W, Set, Set> setM(final Ord o) {
        return lift(F2Functions.setM(this, o));
    }

    /**
     * Promotes this function to a function on Streams.
     *
     * @return This function promoted to transform Streams.
     */
    public final F2W, Stream, Stream> streamM() {
        return lift(F2Functions.streamM(this));
    }

    /**
     * Promotes this function to a function on Trees.
     *
     * @return This function promoted to transform Trees.
     */
    public final F2W, Tree, Tree> treeM() {
        return lift(F2Functions.treeM(this));
    }

    /**
     * Promotes this function to zip two arrays, applying the function lock-step over both Arrays.
     *
     * @return A function that zips two arrays with this function.
     */
    public final F2W, Array, Array> zipArrayM() {
        return lift(F2Functions.zipArrayM(this));
    }

    /**
     * Promotes this function to zip two iterables, applying the function lock-step over both iterables.
     *
     * @return A function that zips two iterables with this function.
     */
    public final F2W, Iterable, Iterable> zipIterableM() {
        return lift(F2Functions.zipIterableM(this));
    }

    /**
     * Promotes this function to zip two lists, applying the function lock-step over both lists.
     *
     * @return A function that zips two lists with this function.
     */
    public final F2W, List, List> zipListM() {
        return lift(F2Functions.zipListM(this));
    }


    /**
     * Promotes this function to zip two streams, applying the function lock-step over both streams.
     *
     * @return A function that zips two streams with this function.
     */
    public final F2W, Stream, Stream> zipStreamM() {
        return lift(F2Functions.zipStreamM(this));
    }

    /**
     * Promotes this function to zip two non-empty lists, applying the function lock-step over both lists.
     *
     * @return A function that zips two non-empty lists with this function.
     */
    public final F2W, NonEmptyList, NonEmptyList> zipNelM() {
        return lift(F2Functions.zipNelM(this));
    }

    /**
     * Promotes this function to zip two sets, applying the function lock-step over both sets.
     *
     * @param o An ordering for the resulting set.
     * @return A function that zips two sets with this function.
     */
    public final F2W, Set, Set> zipSetM(final Ord o) {
        return lift(F2Functions.zipSetM(this, o));
    }

    /**
     * Promotes this function to zip two trees, applying the function lock-step over both trees.
     * The structure of the resulting tree is the structural intersection of the two trees.
     *
     * @return A function that zips two trees with this function.
     */
    public final F2W, Tree, Tree> zipTreeM() {
        return lift(F2Functions.zipTreeM(this));
    }

    /**
     * Promotes this function to zip two zippers, applying the function lock-step over both zippers in both directions.
     * The structure of the resulting zipper is the structural intersection of the two zippers.
     *
     * @return A function that zips two zippers with this function.
     */
    public final F2W, Zipper, Zipper> zipZipperM() {
        return lift(F2Functions.zipZipperM(this));
    }

    /**
     * Promotes this function to zip two TreeZippers, applying the function lock-step over both zippers in all directions.
     * The structure of the resulting TreeZipper is the structural intersection of the two TreeZippers.
     *
     * @return A function that zips two TreeZippers with this function.
     */
    public final F2W, TreeZipper, TreeZipper> zipTreeZipperM() {
        return lift(F2Functions.zipTreeZipperM(this));
    }

    public final  F2W contramapFirst(F f) {
        return lift(F2Functions.contramapFirst(this, f));
    }

    public final  F2W contramapSecond(F f) {
        return lift(F2Functions.contramapSecond(this, f));
    }

    public final  F2W contramap(F f, F g) {
        return lift(F2Functions.contramap(this, f, g));
    }

    public final  F2W map(F f) {
        return lift(F2Functions.map(this, f));
    }


    public static class F2WFunc extends F2W {
        final F2 func;
        public F2WFunc(F2 f) {
            func = f;
        }

        @Override
        public final C f(A a, B b) {
            return func.f(a, b);
        }
    }

    /**
     * Lifts the function into the fully featured function wrapper
     */
    public static  F2W lift(final F2 f) {
        return new F2WFunc<>(f);
    }



}