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

com.aol.cyclops.functionaljava.FromJavaslang Maven / Gradle / Ivy

There is a newer version: 9.0.0-MI7
Show newest version
package com.aol.cyclops.functionaljava;

import java.util.stream.Stream;

import javaslang.Function1;
import javaslang.Function2;
import javaslang.Function3;
import javaslang.Function4;
import javaslang.Function5;
import javaslang.Function6;
import javaslang.Function7;
import javaslang.Function8;
import javaslang.Tuple1;
import javaslang.Tuple2;
import javaslang.Tuple3;
import javaslang.Tuple4;
import javaslang.Tuple5;
import javaslang.Tuple6;
import javaslang.Tuple7;
import javaslang.Tuple8;
import javaslang.control.Either;
import javaslang.control.Option;
import fj.F;
import fj.F2;
import fj.F3;
import fj.F4;
import fj.F5;
import fj.F6;
import fj.F7;
import fj.F8;
import fj.P;
import fj.P1;
import fj.P2;
import fj.P3;
import fj.P4;
import fj.P5;
import fj.P6;
import fj.P7;
import fj.P8;

public class FromJavaslang {
    public static  F f1(Function1 fn) {
        return (t) -> fn.apply(t);
    }

    public static  F2 f2(Function2 fn) {
        return (t, x) -> fn.apply(t, x);
    }

    public static  F3 f3(Function3 fn) {
        return (t1, t2, t3) -> fn.apply(t1, t2, t3);
    }

    public static  F4 f4(Function4 fn) {
        return (t1, t2, t3, t4) -> fn.apply(t1, t2, t3, t4);
    }

    public static  F5 f5(Function5 fn) {
        return (t1, t2, t3, t4, t5) -> fn.apply(t1, t2, t3, t4, t5);
    }

    public static  F6 f6(
            Function6 fn) {
        return (t1, t2, t3, t4, t5, t6) -> fn.apply(t1, t2, t3, t4, t5, t6);
    }

    public static  F7 f7(
            Function7 fn) {
        return (t1, t2, t3, t4, t5, t6, t7) -> fn.apply(t1, t2, t3, t4, t5, t6, t7);
    }

    public static  F8 f8(
            Function8 fn) {
        return (t1, t2, t3, t4, t5, t6, t7, t8) -> fn.apply(t1, t2, t3, t4, t5, t6, t7, t8);
    }

    public static  fj.data.Option option(Option o) {
        if (o.isEmpty())
            return fj.data.Option.none();
        return fj.data.Option.some(o.get());
    }

    public static  fj.data.Either either(Either e) {
        if (e.isLeft())
            return fj.data.Either.left(e.left()
                                        .get());
        else
            return fj.data.Either.right(e.right()
                                         .get());
    }

    public static  P1 tuple(Tuple1 t) {
        return P.p(t._1);
    }

    public static  P2 tuple(Tuple2 t) {
        return P.p(t._1, t._2);
    }

    public static  P3 tuple(Tuple3 t) {
        return P.p(t._1, t._2, t._3);
    }

    public static  P4 tuple(Tuple4 t) {
        return P.p(t._1, t._2, t._3, t._4);
    }

    public static  P5 tuple(Tuple5 t) {
        return P.p(t._1, t._2, t._3, t._4, t._5);
    }

    public static  P6 tuple(Tuple6 t) {
        return P.p(t._1, t._2, t._3, t._4, t._5, t._6);
    }

    public static  P7 tuple(
            Tuple7 t) {
        return P.p(t._1, t._2, t._3, t._4, t._5, t._6, t._7);
    }

    public static  P8 tuple(
            Tuple8 t) {
        return P.p(t._1, t._2, t._3, t._4, t._5, t._6, t._7, t._8);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy