Package io.atlassian.fugue
Class Suppliers
- java.lang.Object
-
- io.atlassian.fugue.Suppliers
-
public class Suppliers extends java.lang.ObjectProvide utility functions for the class of functions that supply a return value when invoked.- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classSuppliers.MemoizingSupplier<A>private static classSuppliers.WeakMemoizingSupplier<A>
-
Constructor Summary
Constructors Constructor Description Suppliers()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.function.Supplier<java.lang.Boolean>alwaysFalse()Supplies false.static <A> java.util.function.Supplier<A>alwaysNull()Always returns null.static java.util.function.Supplier<java.lang.Boolean>alwaysTrue()Supplies true.static <A,B>
java.util.function.Supplier<B>ap(java.util.function.Supplier<A> sa, java.util.function.Supplier<java.util.function.Function<A,B>> sf)Performs function application within a supplier (applicative functor pattern).static <A,B>
java.util.function.Supplier<B>compose(java.util.function.Function<? super A,B> transform, java.util.function.Supplier<A> first)Create a newSupplierby transforming the result calling the firstSupplierstatic <A,B>
java.util.function.Supplier<B>fromFunction(java.util.function.Function<? super A,? extends B> f, A a)Constantly applies the input value to the supplied function, and returns the result.static <A> java.util.function.Supplier<A>fromOption(Option<A> option)Turns an Option into a supplier, but throws an exception if undefined.static <A> java.util.function.Supplier<A>memoize(java.util.function.Supplier<A> supplier)A supplier that memoize the value return by anotherSupplier, whoseSupplier.get()method is guaranteed to be call at most once.static <A> java.util.function.Supplier<A>ofInstance(A a)Creates aSupplierof a constant value.static <A> java.util.function.Supplier<A>weakMemoize(java.util.function.Supplier<A> supplier)A supplier that weakly memoize the value return by anotherSupplier, The returnedSupplieris thread-safe
-
-
-
Method Detail
-
ofInstance
public static <A> java.util.function.Supplier<A> ofInstance(A a)
Creates aSupplierof 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> java.util.function.Supplier<B> compose(java.util.function.Function<? super A,B> transform, java.util.function.Supplier<A> first)Create a newSupplierby transforming the result calling the firstSupplier- Type Parameters:
A- return type of theSupplierto transformB- return type of the newSupplier- Parameters:
transform- function to transform the result of aSupplierof A's to B'sfirst- aSupplierof A's- Returns:
- a new
Supplierreturning B's
-
ap
public static <A,B> java.util.function.Supplier<B> ap(java.util.function.Supplier<A> sa, java.util.function.Supplier<java.util.function.Function<A,B>> sf)Performs function application within a supplier (applicative functor pattern).- Parameters:
sa- suppliersf- 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 java.util.function.Supplier<java.lang.Boolean> alwaysTrue()
Supplies true.- Returns:
- a supplier that always supplies
true.
-
alwaysFalse
public static java.util.function.Supplier<java.lang.Boolean> alwaysFalse()
Supplies false.- Returns:
- a supplier that always supplies
false.
-
alwaysNull
public static <A> java.util.function.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> java.util.function.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
Supplierthat always callsMaybe.get(), which throws an Exception if the option is None - Since:
- 2.0
-
fromFunction
public static <A,B> java.util.function.Supplier<B> fromFunction(java.util.function.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 typeB- the result type- Parameters:
f- the functiona- the value- Returns:
- a
Supplierthat always callsFunction.apply(Object) - Since:
- 2.2
-
memoize
public static <A> java.util.function.Supplier<A> memoize(java.util.function.Supplier<A> supplier)
A supplier that memoize the value return by anotherSupplier, whoseSupplier.get()method is guaranteed to be call at most once. The returnedSupplieris thread-safe- Type Parameters:
A- the type- Parameters:
supplier- the supplier to memoize- Returns:
- the memoizing supplier
-
weakMemoize
public static <A> java.util.function.Supplier<A> weakMemoize(java.util.function.Supplier<A> supplier)
A supplier that weakly memoize the value return by anotherSupplier, The returnedSupplieris thread-safe- Type Parameters:
A- the type- Parameters:
supplier- the supplier to memoize- Returns:
- the weakly memoizing supplier
-
-