public final class Strategy<A>
extends java.lang.Object
Modifier and Type | Method and Description |
---|---|
static <A> Strategy<java.util.concurrent.Callable<A>> |
callableStrategy(Strategy<java.util.concurrent.Callable<A>> s)
Provides a normalising strategy that fully evaluates its Callable argument.
|
static <A> Strategy<A> |
completionStrategy(java.util.concurrent.CompletionService<A> s)
Provides a parallelization strategy that uses a CompletionService to control the method and
degree of parallelism, and where each parallel task's completion is registered with the service.
|
<B> F<B,P1<A>> |
concurry(F<B,A> f)
Promotes a function to a concurrent function.
|
<B,C> F<B,F<C,P1<A>>> |
concurry(F2<B,C,A> f)
Promotes a function of arity-2 to a concurrent function.
|
Strategy<A> |
contramap(F<P1<A>,P1<A>> f)
Maps the given transformation across this strategy's codomain (Invariant Functor pattern).
|
static <A> Effect1<java.util.concurrent.Future<A>> |
discard()
Returns an Effect that waits for a given Future to obtain a value, discarding the value.
|
Strategy<A> |
errorStrategy(Effect1<java.lang.Error> e)
Provides an error-handling strategy.
|
static <A> Strategy<A> |
errorStrategy(Strategy<A> s,
Effect1<java.lang.Error> e)
Provides an error-handling strategy.
|
static <A> Strategy<A> |
executorStrategy(java.util.concurrent.ExecutorService s)
Provides a parallelization strategy that uses an ExecutorService to control the method and
degree of parallelism.
|
F<P1<A>,P1<A>> |
f()
Returns the functional representation of this Strategy, a function that evaluates a product-1.
|
static <A> Strategy<A> |
idStrategy()
Provides a strategy that performs no evaluation of its argument.
|
Strategy<A> |
map(F<P1<A>,P1<A>> f)
Maps the given transformation across this strategy's domain (Invariant Functor pattern).
|
static <A> List<P1<A>> |
mergeAll(List<java.util.concurrent.Future<A>> xs)
Waits for every Future in a list to obtain a value, and collects those values in a list.
|
static <A> F<java.util.concurrent.Future<A>,P1<A>> |
obtain()
Returns a function which returns a product-1 which waits for the given Future to obtain a value.
|
static <A> P1<A> |
obtain(java.util.concurrent.Future<A> t)
Provides a product-1 that waits for the given future to obtain a value.
|
P1<A> |
par(P1<A> a)
Apply the strategy to the given product-1.
|
static <A,B> P1<Array<B>> |
parFlatMap(Strategy<Array<B>> s,
F<A,Array<B>> f,
Array<A> as)
Binds the given function in parallel across the given array, using the given strategy, with a final join.
|
static <A,B> P1<List<B>> |
parFlatMap(Strategy<List<B>> s,
F<A,List<B>> f,
List<A> as)
Binds the given function in parallel across the given list, using the given strategy, with a final join.
|
P1<List<A>> |
parList(List<P1<A>> ps)
Evaluates a list of product-1s in parallel.
|
static <A> P1<List<A>> |
parListChunk(Strategy<List<A>> s,
int chunkLength,
List<P1<A>> as)
Sequentially evaluates chunks (sub-sequences) of a list in parallel.
|
<B> P1<Array<A>> |
parMap(F<B,A> f,
Array<B> bs)
Maps the given function over the given array in parallel using this strategy.
|
<B> P1<List<A>> |
parMap(F<B,A> f,
List<B> bs)
Maps the given function over the given list in parallel using this strategy.
|
<B> Array<A> |
parMap1(F<B,A> f,
Array<B> bs)
A strict version of parMap over arrays.
|
<B> List<A> |
parMap1(F<B,A> f,
List<B> bs)
A strict version of parMap over lists.
|
<B> F<F<B,A>,F<Array<B>,P1<Array<A>>>> |
parMapArray()
First-class version of parMap on arrays.
|
<B> F<Array<B>,P1<Array<A>>> |
parMapArray(F<B,A> f)
Promotes a function to a parallel function on arrays using this strategy.
|
<B> F<F<B,A>,F<Array<B>,Array<A>>> |
parMapArray1()
First-class version of parMap1 on arrays (parallel array functor).
|
<B> F<F<B,A>,F<List<B>,P1<List<A>>>> |
parMapList()
First-class version of parMap on lists.
|
<B> F<List<B>,P1<List<A>>> |
parMapList(F<B,A> f)
Promotes a function to a parallel function on lists using this strategy.
|
<B> F<F<B,A>,F<List<B>,List<A>>> |
parMapList1()
First-class version of parMap1 on lists (parallel list functor).
|
<B,C> F2<Array<B>,Array<C>,P1<Array<A>>> |
parZipArrayWith(F2<B,C,A> f)
Lifts a given function of arity-2 so that it zips together two arrays in parallel,
using this strategy, calling the function once for each corresponding pair in the arrays, position-wise.
|
<B,C> F2<List<B>,List<C>,P1<List<A>>> |
parZipListWith(F2<B,C,A> f)
Lifts a given function of arity-2 so that it zips together two lists in parallel,
using this strategy, calling the function once for each corresponding pair in the lists, position-wise.
|
<B,C> P1<Array<A>> |
parZipWith(F2<B,C,A> f,
Array<B> bs,
Array<C> cs)
Zips together two arrays in parallel using a given function, with this strategy.
|
<B,C> P1<List<A>> |
parZipWith(F2<B,C,A> f,
List<B> bs,
List<C> cs)
Zips together two lists in parallel using a given function, with this strategy.
|
static <A> Strategy<A> |
seqStrategy()
Provides a strategy that performs sequential (non-concurrent) evaluation of its argument.
|
static <A> Strategy<A> |
simpleThreadStrategy()
Provides a simple parallelization strategy that creates, and discards, a new thread for
every evaluation.
|
static <A> Strategy<A> |
strategy(F<P1<A>,P1<A>> f)
Constructs a strategy from the given evaluation function.
|
<B> Strategy<B> |
xmap(F<P1<A>,P1<B>> f,
F<P1<B>,P1<A>> g)
Maps the given bijective transformation across this strategy (Exponential Functor pattern).
|
public F<P1<A>,P1<A>> f()
public static <A> Strategy<A> strategy(F<P1<A>,P1<A>> f)
f
- The execution function for the strategypublic P1<A> par(P1<A> a)
a
- A P1 to evaluate according to this strategy.public <B> F<B,P1<A>> concurry(F<B,A> f)
f
- A function to promote to a concurrent function.public <B,C> F<B,F<C,P1<A>>> concurry(F2<B,C,A> f)
f
- The function to promote to a concurrent function.public static <A> List<P1<A>> mergeAll(List<java.util.concurrent.Future<A>> xs)
xs
- The list of Futures from which to get values.public P1<List<A>> parList(List<P1<A>> ps)
ps
- A list to evaluate in parallel.public <B> P1<List<A>> parMap(F<B,A> f, List<B> bs)
f
- A function to map over the given list in parallel.bs
- A list over which to map the given function in parallel.public <B> P1<Array<A>> parMap(F<B,A> f, Array<B> bs)
f
- A function to map over the given array in parallel.bs
- An array over which to map the given function in parallel.public <B> List<A> parMap1(F<B,A> f, List<B> bs)
f
- A function to map over the given list in parallel.bs
- A list over which to map the given function in parallel.public <B> Array<A> parMap1(F<B,A> f, Array<B> bs)
f
- A function to map over the given array in parallel.bs
- An array over which to map the given function in parallel.public <B> F<List<B>,P1<List<A>>> parMapList(F<B,A> f)
f
- A function to transform into a parallel function on lists.public <B> F<F<B,A>,F<List<B>,P1<List<A>>>> parMapList()
public <B> F<F<B,A>,F<List<B>,List<A>>> parMapList1()
public <B> F<Array<B>,P1<Array<A>>> parMapArray(F<B,A> f)
f
- A function to transform into a parallel function on arrays.public <B> F<F<B,A>,F<Array<B>,P1<Array<A>>>> parMapArray()
public <B> F<F<B,A>,F<Array<B>,Array<A>>> parMapArray1()
public static <A,B> P1<List<B>> parFlatMap(Strategy<List<B>> s, F<A,List<B>> f, List<A> as)
s
- The strategy to use for parallelization.f
- The function to bind across the given list.as
- The list across which to bind the given function.public static <A,B> P1<Array<B>> parFlatMap(Strategy<Array<B>> s, F<A,Array<B>> f, Array<A> as)
s
- The strategy to use for parallelization.f
- The function to bind across the given array.as
- The array across which to bind the given function.public static <A> P1<List<A>> parListChunk(Strategy<List<A>> s, int chunkLength, List<P1<A>> as)
s
- The strategy to use for parallelization.chunkLength
- The length of each sequence.as
- The list to evaluate in parallel chunks.public <B,C> P1<List<A>> parZipWith(F2<B,C,A> f, List<B> bs, List<C> cs)
f
- The function of arity-2 with which to zip.bs
- A list to zip with the given function.cs
- A list to zip with the given function.public <B,C> P1<Array<A>> parZipWith(F2<B,C,A> f, Array<B> bs, Array<C> cs)
f
- The function of arity-2 with which to zip.bs
- A array to zip with the given function.cs
- A array to zip with the given function.public <B,C> F2<List<B>,List<C>,P1<List<A>>> parZipListWith(F2<B,C,A> f)
f
- The function of arity-2 with which to zip.public <B,C> F2<Array<B>,Array<C>,P1<Array<A>>> parZipArrayWith(F2<B,C,A> f)
f
- The function of arity-2 with which to zip.public static <A> F<java.util.concurrent.Future<A>,P1<A>> obtain()
public static <A> P1<A> obtain(java.util.concurrent.Future<A> t)
t
- A Future for which to wait.public static <A> Effect1<java.util.concurrent.Future<A>> discard()
public static <A> Strategy<A> simpleThreadStrategy()
public static <A> Strategy<A> executorStrategy(java.util.concurrent.ExecutorService s)
s
- The ExecutorService to use for scheduling evaluations.public static <A> Strategy<A> completionStrategy(java.util.concurrent.CompletionService<A> s)
s
- The CompletionService to use for scheduling evaluations and detect their completion.public static <A> Strategy<A> seqStrategy()
public static <A> Strategy<A> idStrategy()
public <B> Strategy<B> xmap(F<P1<A>,P1<B>> f, F<P1<B>,P1<A>> g)
f
- A transformation from this strategy's codomain to the resulting strategy's codomain.g
- A transformation from the resulting strategy's domain to this strategy's domain.public Strategy<A> map(F<P1<A>,P1<A>> f)
f
- A transformation from this strategy's codomain to the resulting strategy's codomain.public Strategy<A> contramap(F<P1<A>,P1<A>> f)
f
- A transformation from the resulting strategy's domain to this strategy's domain.public Strategy<A> errorStrategy(Effect1<java.lang.Error> e)
e
- The effect that should handle errors.public static <A> Strategy<A> errorStrategy(Strategy<A> s, Effect1<java.lang.Error> e)
s
- The strategy to equip with an error-handling effect.e
- The effect that should handle errors.public static <A> Strategy<java.util.concurrent.Callable<A>> callableStrategy(Strategy<java.util.concurrent.Callable<A>> s)
s
- A non-normalising strategy to use for the evaluation.