Package io.atlassian.fugue
Class Suppliers
java.lang.Object
io.atlassian.fugue.Suppliers
Provide utility functions for the class of functions that supply a return
value when invoked.
- Since:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final classprivate static final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSupplies false.static <A> Supplier<A> Always returns null.Supplies true.static <A,B> Supplier <B> Performs function application within a supplier (applicative functor pattern).static <A,B> Supplier <B> 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.static <A> Supplier<A> fromOption(Option<A> option) Turns an Option into a supplier, but throws an exception if undefined.static <A> Supplier<A> A supplier that memoize the value return by anotherSupplier, whoseSupplier.get()method is guaranteed to be call at most once.static <A> Supplier<A> ofInstance(A a) Creates aSupplierof a constant value.static <A> Supplier<A> weakMemoize(Supplier<A> supplier)
-
Constructor Details
-
Suppliers
public Suppliers()
-
-
Method Details
-
ofInstance
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
-
ap
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
Supplies true.- Returns:
- a supplier that always supplies
true.
-
alwaysFalse
Supplies false.- Returns:
- a supplier that always supplies
false.
-
alwaysNull
Always returns null. Not a very good idea.- Type Parameters:
A- the type- Returns:
- a supplier that always supplies
null.
-
fromOption
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
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
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
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
-