fj.data.Java8 Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of functionaljava-java8 Show documentation
Show all versions of functionaljava-java8 Show documentation
Functional Java is an open source library that supports closures for the Java programming language
The newest version!
package fj.data;
import java.util.Iterator;
import java.util.Optional;
import java.util.Spliterators;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.StreamSupport;
import fj.F;
import fj.F2;
import fj.P;
import fj.P1;
import fj.Try;
import fj.Unit;
import fj.function.Try0;
import fj.function.Try1;
import fj.function.Try2;
/**
* Created by mperry on 3/06/2014.
*/
public final class Java8 {
private Java8() {
throw new UnsupportedOperationException();
}
public static P1 Supplier_P1(final Supplier s) {
return P.lazy(s::get);
}
public static F, P1> Supplier_P1() {
return Java8::Supplier_P1;
}
public static Supplier P1_Supplier(final P1 p) {
return p::_1;
}
public static F, Supplier> P1_Supplier() {
return Java8::P1_Supplier;
}
public static F Function_F(final Function f) {
return f::apply;
}
public static F, F> Function_F() {
return Java8::Function_F;
}
public static Function F_Function(final F f) {
return f::f;
}
public static F, Function> F_Function() {
return Java8::F_Function;
}
public static F2 BiFunction_F2(final BiFunction f) {
return f::apply;
}
public static F, F2> BiFunction_F2() {
return Java8::BiFunction_F2;
}
public static BiFunction F2_BiFunction(final F2 f) {
return f::f;
}
public static F, BiFunction> F2_BiFunction() {
return Java8::F2_BiFunction;
}
public static Supplier> TryCatch0_Supplier(final Try0 t) {
return () -> Try.f(t)._1();
}
public static F, Supplier>> TryCatch0_Supplier() {
return Java8::TryCatch0_Supplier;
}
public static Function> TryCatch1_Function(final Try1 t) {
return a -> Try.f(t).f(a);
}
public static F, Function>> TryCatch1_Function() {
return Java8::TryCatch1_Function;
}
public static BiFunction> TryCatch2_BiFunction(final Try2 t) {
return (a, b) -> Try.f(t).f(a, b);
}
public static F, BiFunction>> TryCatch2_BiFunction() {
return Java8::TryCatch2_BiFunction;
}
public static java.util.stream.Stream List_JavaStream(final List list) {
return Iterable_JavaStream(list);
}
public static Option Optional_Option(final Optional o) {
return o.isPresent() ? Option.some(o.get()) : Option.none();
}
public static F, Option> Optional_Option() {
return Java8::Optional_Option;
}
/**
* Convert an Option to {@link Optional}. Will throw a {@link NullPointerException} if the Option is some(null).
*/
public static Optional Option_Optional(final Option o) {
return o.option(Optional.empty(), Optional::of);
}
public static F