Package fj.control.parallel
Class Promise<A>
java.lang.Object
fj.control.parallel.Promise<A>
Represents a non-blocking future value. Products, functions, and actors, given to the methods on this class,
are executed concurrently, and the Promise serves as a handle on the result of the computation. Provides monadic
operations so that future computations can be combined
Author: Runar
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<B> Promise
<B> Performs function application within a promise (applicative functor pattern).<B,
C> Promise <C> Binds the given function to this promise and the given promise, with a final join.<B> Promise
<B> Binds the given function over this promise, with a final join.<B,
C> Promise <C> Binds the given function to this promise and the given promise, with a final join.claim()
Waits if necessary for the computation to complete, and then retrieves its result.Waits if necessary for the computation to complete, and then retrieves its result.<B> Promise
<B> Binds the given function across a promise of this promise (Comonad pattern).cojoin()
Duplicates this promise to a promise of itself (Comonad pattern).<B> Promise
<B> Provides a promise to apply the given function to this promise's future value (covariant functor pattern).Promotes any function to a transformation between promises (covariant functor pattern).Performs a right-fold reduction across a list in constant stack space.Performs a right-fold reduction across a Stream in constant stack space.boolean
Returns true if this promise has been fulfilled.static <A> Promise
<A> Turns a promise of a promise into just a promise.static <A> Promise
<A> Turns a product of a promise into just a promise.Promotes a function of arity-2 to a function on promises.private static <A> Promise
<A> Provides a first-class unit function for promises.Transforms any function so that it returns a promise of a value instead of an actual value.static <A> Promise
<A> Promises to provide the value of the given 1-product, in the future.Provides a promise to call the given Callable in the future.First-class version of the sequence function through a List.Turns a List of promises into a single promise of a List.Turns a Stream of promises into a single promise of a Stream.Transforms a product of a promise to a promise of a product.First-class version of the sequence function through a Stream.<B> Stream
<B> Applies a stream of comonadic functions to this promise, returning a stream of values.void
Promises to send a value to the given actor in the future.
-
Field Details
-
actor
-
s
-
l
-
v
-
waiting
-
-
Constructor Details
-
Promise
-
-
Method Details
-
mkPromise
-
promise
Promises to provide the value of the given 1-product, in the future. Represents the unit function for promises.- Parameters:
s
- The strategy with which to fulfil the promise.a
- The 1-product to evaluate concurrently.- Returns:
- A promise representing the future result of evaluating the given 1-product.
-
promise
Provides a first-class unit function for promises.- Parameters:
s
- The strategy with which to fulfil promises.- Returns:
- A function that, given a 1-product, yields a promise of that product's value.
-
promise
Provides a promise to call the given Callable in the future.- Parameters:
s
- The strategy with which to fulfil the promise.a
- The Callable to evaluate concurrently.- Returns:
- A promise of a new Callable that will return the result of calling the given Callable.
-
promise
Transforms any function so that it returns a promise of a value instead of an actual value. Represents the Kleisli arrow for the Promise monad.- Parameters:
s
- The strategy with which to fulfil the promise.f
- The function to turn into a promise-valued function.- Returns:
- The given function transformed into a function that returns a promise.
-
to
Promises to send a value to the given actor in the future.- Parameters:
a
- An actor that will receive this Promise's value in the future.
-
fmap
Provides a promise to apply the given function to this promise's future value (covariant functor pattern).- Parameters:
f
- The function to apply to this promise's future value.- Returns:
- A promise representing the future result of applying the given function to this promised value.
-
fmap_
Promotes any function to a transformation between promises (covariant functor pattern).- Parameters:
f
- The function to promote to a transformation between promises.- Returns:
- That function lifted to a function on Promises.
-
join
Turns a promise of a promise into just a promise. The join function for the Promise monad. Promise to give it a Promise of an A, and it will promise you an A in return.- Parameters:
p
- A promise of a promise.- Returns:
- The promised promise.
-
join
Turns a product of a promise into just a promise. Does not block on the product by calling it, but creates a new promise with a final join.- Parameters:
s
- The strategy with which to fulfil the promise.p
- A product-1 of a promise to turn into just a promise.- Returns:
- The joined promise.
-
bind
Binds the given function over this promise, with a final join. The bind function for the Promise monad.- Parameters:
f
- The function to bind over this promise.- Returns:
- The result of applying the given function to this promised value.
-
apply
Performs function application within a promise (applicative functor pattern).- Parameters:
pf
- The promised function to apply.- Returns:
- A new promise after applying the given promised function to this promise.
-
bind
Binds the given function to this promise and the given promise, with a final join.- Parameters:
pb
- A promise with which to bind the given function.f
- The function to apply to the given promised values.- Returns:
- A new promise after performing the map, then final join.
-
bind
Binds the given function to this promise and the given promise, with a final join.- Parameters:
p
- A promise with which to bind the given function.f
- The function to apply to the given promised values.- Returns:
- A new promise after performing the map, then final join.
-
liftM2
Promotes a function of arity-2 to a function on promises.- Parameters:
f
- The function to promote.- Returns:
- A function of arity-2 promoted to map over promises.
-
sequence
Turns a List of promises into a single promise of a List.- Parameters:
s
- The strategy with which to sequence the promises.as
- The list of promises to transform.- Returns:
- A single promise for the given List.
-
sequence
First-class version of the sequence function through a List.- Parameters:
s
- The strategy with which to sequence a given list of promises.- Returns:
- A function that turns a list of promises into a single promise of a list.
-
sequence
Turns a Stream of promises into a single promise of a Stream.- Parameters:
s
- The strategy with which to sequence the promises.as
- The Stream of promises to transform.- Returns:
- A single promise for the given Stream.
-
sequenceS
First-class version of the sequence function through a Stream.- Parameters:
s
- The strategy with which to sequence a given Stream of promises.- Returns:
- A function that turns a list of promises into a single promise of a Stream..
-
sequence
Transforms a product of a promise to a promise of a product.- Parameters:
s
- The strategy with which to traverse the promise.p
- A product of a promise to traverse.- Returns:
- A promised product.
-
foldRight
Performs a right-fold reduction across a list in constant stack space.- Parameters:
s
- The strategy with which to fold the list.f
- The function to apply on each element of the list.b
- The beginning value to start the application from.- Returns:
- The final result after the right-fold reduction.
-
foldRightS
Performs a right-fold reduction across a Stream in constant stack space.- Parameters:
s
- The strategy with which to fold the Stream.f
- The function to apply on each element of the Stream.b
- The beginning value to start the application from.- Returns:
- The final result after the right-fold reduction.
-
claim
Waits if necessary for the computation to complete, and then retrieves its result.- Returns:
- The promised value.
-
claim
Waits if necessary for the computation to complete, and then retrieves its result.- Parameters:
timeout
- the maximum time to waitunit
- the time unit of the timeout argument- Returns:
- The promised value, or none if the timeout was reached.
-
isFulfilled
public boolean isFulfilled()Returns true if this promise has been fulfilled.- Returns:
- true if this promise has been fulfilled.
-
cobind
Binds the given function across a promise of this promise (Comonad pattern).- Parameters:
f
- A function to apply within a new promise of this promise.- Returns:
- A new promise of the result of applying the given function to this promise.
-
cojoin
Duplicates this promise to a promise of itself (Comonad pattern).- Returns:
- a promise of this promise.
-
sequenceW
Applies a stream of comonadic functions to this promise, returning a stream of values.- Parameters:
fs
- A stream of functions to apply to this promise.- Returns:
- A stream of the results of applying the given stream of functions to this promise.
-