Class Functions

java.lang.Object
org.opencastproject.util.data.functions.Functions

public final class Functions extends Object
General purpose functions, especially function transformations.
  • Field Details

    • noop

      public static final Effect0 noop
      Noop effect.
    • run

      public static final Effect<Effect0> run
      Create an effect that runs its argument.
  • Method Details

    • o

      public static <A, B, C> Function<A,C> o(Function<? super B,? extends C> f, Function<? super A,? extends B> g)
      Function composition: f . g = f(g(x)) = o(f, g)
    • o

      public static <A, B> Function0<B> o(Function<? super A,? extends B> f, Function0<? extends A> g)
      Function composition: f . g = f(g) = o(f, g)
    • then

      public static <A, B, C> Function<A,C> then(Function<? super A,? extends B> f, Function<? super B,? extends C> g)
      Left to right composition: f then g = g(f(x))
    • then

      public static <A, B> Function0<B> then(Function0<? extends A> f, Function<? super A,? extends B> g)
      Left to right composition: f then g = g(f)
    • then

      public static <A, B> Function0<B> then(Function0<? extends A> f, Function0<? extends B> g)
      Apply f and ignore its result, then apply g.
    • rethrow

      public static <A, B> Function<A,B> rethrow(Function<? super A,? extends B> f, Function<? super Exception,? extends Exception> transformer)
      Create a new function from f decorated with an exception transformer. Any exception that occurs during application of f is passed to transformer whose return value is then being thrown.
    • handle

      public static <A, B> Function<A,B> handle(Function<? super A,? extends B> f, Function<? super Exception,? extends B> handler)
      Create a new function from f decorated with an exception handler. Any exception that occurs during application of f is passed to handler whose return value is then being returned.
    • either

      public static <A, B, C> Function<A,Either<C,B>> either(Function<? super A,? extends B> f, Function<? super Exception,? extends C> handler)
      Create a new function from f decorated with an exception handler. The new function either returns the value of f or in case of an exception being thrown on the application of f the return value of handler.
    • curry

      public static <A, B, C> Function<B,C> curry(Function2<? super A,? super B,? extends C> f, A a)
      Curry a function of arity 2.
    • curry

      public static <A, B, C> Function<A,Function<B,C>> curry(Function2<? super A,? super B,? extends C> f)
      Curry a function of arity 2. (a, b) -gt; c =gt; a -gt; b -gt; c
    • uncurry

      public static <A, B, C> Function2<A,B,C> uncurry(Function<? super A,Function<B,C>> f)
      Uncurry to a function of arity 2. a -gt; b -gt; c =gt; (a, b) -gt; c
    • curry

      public static <A, B> Function0<B> curry(Function<? super A,? extends B> f, A a)
      Curry a function of arity 1.
    • curry

      public static <A, B> Function<A,Function0<B>> curry(Function<A,B> f)
      Curry a function of arity 1.
    • flip

      public static <A, B, C> Function2<B,A,C> flip(Function2<? super A,? super B,? extends C> f)
      Flip arguments of a function of arity 2.
    • toEffect

      public static <A, B> Effect<A> toEffect(Function<? super A,? extends B> f)
      Turn a function into an effect by discarding its result.
    • toPredicate

      public static <A> Predicate<A> toPredicate(Function<? super A,Boolean> f)
    • identity

      public static <A> Function<A,A> identity()
      Identity function.
    • identity

      public static <A> Function<A,A> identity(A example)
      Identity function. The type is based on the type of the example object to save some nasty typing, e.g. Function.<Integer>identity() vs. identity(0) Please note that this constructor is only due to Java's insufficient type inference.
    • identity

      public static <A> Function<A,A> identity(Class<A> clazz)
      Identity function.
      Parameters:
      clazz - to describe the functions's type
    • co

      public static <A, B> Function<A,B> co(Function<? super A,? extends B> f)
      Pure functions are covariant in their result type.
    • contra

      public static <A, B> Function<A,B> contra(Function<? super A,B> f)
      Pure functions are contravariant in their argument type.
    • variant

      public static <A, B> Function<A,B> variant(Function<? super A,? extends B> f)
      Pure functions are covariant in their result type and contravariant in their argument type.
    • chuck

      public static <A> A chuck(Throwable 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
    • toGuava

      public static <A, B> com.google.common.base.Function<A,B> toGuava(Function<? super A,? extends B> f)
      Convert function f into a guava function.