Class Suppliers

java.lang.Object
io.atlassian.fugue.Suppliers

public class Suppliers extends Object
Provide utility functions for the class of functions that supply a return value when invoked.
Since:
1.0
  • Constructor Details

    • Suppliers

      public Suppliers()
  • Method Details

    • ofInstance

      public static <A> Supplier<A> ofInstance(A a)
      Creates a Supplier of a constant value.
      Type Parameters:
      A - the type
      Parameters:
      a - the constant value to supply
      Returns:
      a supplier that always supplies instance.
    • compose

      public static <A, B> Supplier<B> compose(Function<? super A,B> transform, Supplier<A> first)
      Create a new Supplier by transforming the result calling the first Supplier
      Type Parameters:
      A - return type of the Supplier to transform
      B - return type of the new Supplier
      Parameters:
      transform - function to transform the result of a Supplier of A's to B's
      first - a Supplier of A's
      Returns:
      a new Supplier returning B's
    • ap

      public static <A, B> Supplier<B> ap(Supplier<A> sa, Supplier<Function<A,B>> sf)
      Performs function application within a supplier (applicative functor pattern).
      Parameters:
      sa - supplier
      sf - The Supplier function to apply.
      Returns:
      A new Supplier after applying the given Supplier function to the first argument.
      Since:
      4.0
    • alwaysTrue

      public static Supplier<Boolean> alwaysTrue()
      Supplies true.
      Returns:
      a supplier that always supplies true.
    • alwaysFalse

      public static Supplier<Boolean> alwaysFalse()
      Supplies false.
      Returns:
      a supplier that always supplies false.
    • alwaysNull

      public static <A> Supplier<A> alwaysNull()
      Always returns null. Not a very good idea.
      Type Parameters:
      A - the type
      Returns:
      a supplier that always supplies null.
    • fromOption

      public static <A> Supplier<A> fromOption(Option<A> option)
      Turns an Option into a supplier, but throws an exception if undefined. Not a very good idea.
      Type Parameters:
      A - the type
      Parameters:
      option - the option to attempt to get values from
      Returns:
      a Supplier that always calls Maybe.get(), which throws an Exception if the option is None
      Since:
      2.0
    • fromFunction

      public static <A, B> Supplier<B> fromFunction(Function<? super A,? extends B> f, A a)
      Constantly applies the input value to the supplied function, and returns the result.
      Type Parameters:
      A - the input type
      B - the result type
      Parameters:
      f - the function
      a - the value
      Returns:
      a Supplier that always calls Function.apply(Object)
      Since:
      2.2
    • memoize

      public static <A> Supplier<A> memoize(Supplier<A> supplier)
      A supplier that memoize the value return by another Supplier, whose Supplier.get() method is guaranteed to be call at most once. The returned Supplier is thread-safe
      Type Parameters:
      A - the type
      Parameters:
      supplier - the supplier to memoize
      Returns:
      the memoizing supplier
    • weakMemoize

      public static <A> Supplier<A> weakMemoize(Supplier<A> supplier)
      A supplier that weakly memoize the value return by another Supplier , The returned Supplier is thread-safe
      Type Parameters:
      A - the type
      Parameters:
      supplier - the supplier to memoize
      Returns:
      the weakly memoizing supplier