@Override public Option<String> apply(A a) { return asString(a); } };
@Override public Option<String> apply(String a) { return trimToNone(a); } };
/** * Identity function. * * @param clazz * to describe the functions's type */ public static <A> Function<A, A> identity(Class<A> clazz) { return identity(); }
@Override public B apply(Throwable throwable) { return chuck(throwable); } };
@Override public Function<A, B> apply(Function<A, ? extends B> f) { return co(f); } };
/** Currying. */ public Function0<B> curry(final A a) { return Functions.curry(this, a); }
/** Turn this function into an effect by discarding its result. */ public Effect<A> toEffect() { return Functions.toEffect(this); }
/** Apply this function and ignore its result, then apply <code>f</code>. */ public <B> Function0<B> then(final Function0<B> f) { return Functions.then(Function0.this, f); }
/** Function composition. <code>g.o(f).apply(x) == g(f(x))</code> */ public <C> Function<C, B> o(final Function<? super C, ? extends A> f) { return Functions.o(this, f); }
/** * Throw a checked exception like a RuntimeException removing any needs to declare a throws clause. * * This technique has been described by James Iry at * http://james-iry.blogspot.de/2010/08/on-removing-java-checked-exceptions-by.html */ public static <A> A chuck(Throwable t) { return Misc.<RuntimeException, A> castGeneric(t); }
/** * Throw a checked exception like a RuntimeException removing any needs to declare a throws clause. * * This technique has been described by James Iry at * http://james-iry.blogspot.de/2010/08/on-removing-java-checked-exceptions-by.html */ public static <A> A chuck(Throwable t) { return Functions.<RuntimeException, A> castGeneric(t); }
/** @see Functions#rethrow(Function, Function) */ public Function<A, B> rethrow(final Function<? super Exception, ? extends Exception> transformer) { return Functions.rethrow(this, transformer); }
/** @see Functions#either(Function, Function) */ public <X> Function<A, Either<X, B>> either(final Function<Exception, X> handler) { return Functions.either(this, handler); }
/** Convert this function into a google guava function. */ public com.google.common.base.Function<A, B> toGuava() { return Functions.toGuava(this); }
@Override public A apply(Object o) { return cast(o, ev); } };
/** * Identity function. The type is based on the type of the example object to save some nasty typing, e.g. * <code>Function.<Integer>identity()</code> vs. <code>identity(0)</code> * * Please note that this constructor is only due to Java's insufficient type inference. */ public static <A> Function<A, A> identity(A example) { return identity(); }
/** Currying. */ public Function<A, Function0<B>> curry() { return Functions.curry(this); }
/** Turn this function into an effect by discarding its result. */ public Effect0 toEffect() { return Functions.toEffect(this); }
/** Apply this function, then pass the result to <code>f</code>. */ public <B> Function0<B> then(final Function<A, B> f) { return Functions.then(Function0.this, f); }
/** Function composition. <code>g.o(f).apply() == g(f())</code> */ public Function0<B> o(final Function0<? extends A> f) { return Functions.o(this, f); }