Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.

fj.control.parallel
Class ParModule

java.lang.Object
  extended by fj.control.parallel.ParModule

public final class ParModule
extends Object

A module of higher-order concurrency features.


Method Summary
<A> F<Effect<A>,QueueActor<A>>
actor()
          A first-class constructor of actors.
<A> QueueActor<A>
actor(Effect<A> e)
          Creates a concurrent actor that is guaranteed to process only one message at a time.
<A> F<Effect<A>,Actor<A>>
effect()
          A first-class constructor of concurrent effects, as actors that don't guarantee ordering of messages.
<A> Actor<A>
effect(Effect<A> e)
          Creates a very fast concurrent effect, as an actor that does not guarantee ordering of its messages.
<A,B> F<F<A,Promise<B>>,F<List<A>,Promise<List<B>>>>
mapList()
          First-class function that maps a concurrent function over a List inside a promise.
<A,B> Promise<List<B>>
mapM(List<A> as, F<A,Promise<B>> f)
          Takes a Promise-valued function and applies it to each element in the given List, yielding a promise of a List of results.
<A,B> Promise<P1<B>>
mapM(P1<A> a, F<A,Promise<B>> f)
          Maps a concurrent function over a Product-1 inside a Promise.
<A,B> Promise<Stream<B>>
mapM(Stream<A> as, F<A,Promise<B>> f)
          Takes a Promise-valued function and applies it to each element in the given Stream, yielding a promise of a Stream of results.
<A,B> F<F<A,Promise<B>>,F<Stream<A>,Promise<Stream<B>>>>
mapStream()
          First-class function that maps a concurrent function over a Stream inside a promise.
<A,B> Promise<NonEmptyList<B>>
parExtend(NonEmptyList<A> as, F<NonEmptyList<A>,B> f)
          Maps the given function across all sublists of the given NonEmptyList in parallel.
<A,B> Promise<Tree<B>>
parExtend(Tree<A> ta, F<Tree<A>,B> f)
          Maps the given function across all subtrees of the given Tree in parallel.
<A,B> Promise<TreeZipper<B>>
parExtend(TreeZipper<A> za, F<TreeZipper<A>,B> f)
          Maps the given function across all positions of the given TreeZipper in parallel.
<A,B> Promise<Zipper<B>>
parExtend(Zipper<A> za, F<Zipper<A>,B> f)
          Maps the given function across all positions of the given zipper in parallel.
<A,B> Promise<Array<B>>
parFlatMap(Array<A> as, F<A,Array<B>> f)
          Binds an Array-valued function across an Array in parallel, concatenating the results into a new Array.
<A,B> Promise<Iterable<B>>
parFlatMap(Iterable<A> as, F<A,Iterable<B>> f)
          Binds an Iterable-valued function across an Iterable in parallel, concatenating the results into a new Iterable.
<A,B> Promise<List<B>>
parFlatMap(List<A> as, F<A,List<B>> f)
          Binds a list-valued function across a list in parallel, concatenating the results into a new list.
<A,B> Promise<Stream<B>>
parFlatMap(Stream<A> as, F<A,Stream<B>> f)
          Binds a Stream-valued function across a Stream in parallel, concatenating the results into a new Stream.
<A,B> Promise<B>
parFoldMap(Iterable<A> as, F<A,B> map, Monoid<B> reduce)
          Maps with the given function across the given iterable in parallel, while folding with the given monoid.
<A,B> Promise<B>
parFoldMap(Iterable<A> as, F<A,B> map, Monoid<B> reduce, F<Iterable<A>,P2<Iterable<A>,Iterable<A>>> chunking)
          Maps with the given function across chunks of the given Iterable in parallel, while folding with the given monoid.
<A,B> Promise<B>
parFoldMap(Stream<A> as, F<A,B> map, Monoid<B> reduce)
          Maps with the given function across the given stream in parallel, while folding with the given monoid.
<A,B> Promise<B>
parFoldMap(Stream<A> as, F<A,B> map, Monoid<B> reduce, F<Stream<A>,P2<Stream<A>,Stream<A>>> chunking)
          Maps with the given function across chunks of the given stream in parallel, while folding with the given monoid.
<A,B> Promise<Array<B>>
parMap(Array<A> as, F<A,B> f)
          Maps across an Array in parallel.
<A,B> Promise<Iterable<B>>
parMap(Iterable<A> as, F<A,B> f)
          Maps across an Iterable in parallel.
<A,B> Promise<List<B>>
parMap(List<A> as, F<A,B> f)
          Maps across a list in parallel.
<A,B> Promise<NonEmptyList<B>>
parMap(NonEmptyList<A> as, F<A,B> f)
          Maps across a nonempty list in parallel.
<A,B> Promise<Stream<B>>
parMap(Stream<A> as, F<A,B> f)
          Maps across a Stream in parallel.
<A,B> Promise<Tree<B>>
parMap(Tree<A> ta, F<A,B> f)
          Maps a function across a Tree in parallel.
<A,B> Promise<TreeZipper<B>>
parMap(TreeZipper<A> za, F<A,B> f)
          Maps a function across a TreeZipper in parallel.
<A,B> Promise<Zipper<B>>
parMap(Zipper<A> za, F<A,B> f)
          Maps a function across a Zipper in parallel.
<A,B> F<F<A,B>,F<Array<A>,Promise<Array<B>>>>
parMapArray()
          A first-class function that maps another function across an array in parallel.
<A,B> F<F<A,B>,F<Iterable<A>,Promise<Iterable<B>>>>
parMapIterable()
          A first-class function that maps another function across an iterable in parallel.
<A,B> F<F<A,B>,F<List<A>,Promise<List<B>>>>
parMapList()
          A first-class function that maps another function across a list in parallel.
<A,B> F<F<A,B>,F<Stream<A>,Promise<Stream<B>>>>
parMapStream()
          A first-class function that maps another function across a stream in parallel.
<A,B> F<F<A,B>,F<Tree<A>,Promise<Tree<B>>>>
parMapTree()
          A first-class function that maps across a Tree in parallel.
static ParModule parModule(Strategy<Unit> u)
          Constructor method for ParModule
<A,B,C> Promise<Array<C>>
parZipWith(Array<A> as, Array<B> bs, F<A,F<B,C>> f)
          Zips two arrays together with a given function, in parallel.
<A,B,C> Promise<Iterable<C>>
parZipWith(Iterable<A> as, Iterable<B> bs, F<A,F<B,C>> f)
          Zips two iterables together with a given function, in parallel.
<A,B,C> Promise<List<C>>
parZipWith(List<A> as, List<B> bs, F<A,F<B,C>> f)
          Zips two lists together with a given function, in parallel.
<A,B,C> Promise<Stream<C>>
parZipWith(Stream<A> as, Stream<B> bs, F<A,F<B,C>> f)
          Zips two streams together with a given function, in parallel.
<A> F<P1<A>,Promise<A>>
promise()
          Returns a function that evaluates a given product concurrently and returns a Promise of the result.
<A,B> F<A,Promise<B>>
promise(F<A,B> f)
          Promotes the given function to a concurrent function that returns a Promise.
<A,B,C> F2<A,B,Promise<C>>
promise(F2<A,B,C> f)
          Promotes the given function to a concurrent function that returns a Promise.
<A> Promise<A>
promise(P1<A> p)
          Evaluates the given product concurrently and returns a Promise of the result.
<A,B> F<F<A,B>,F<A,Promise<B>>>
promisePure()
          Returns a function that promotes a given function to a concurrent function that returns a Promise.
<A> Promise<List<A>>
sequence(List<Promise<A>> ps)
          List iteration inside a Promise.
<A> Promise<P1<A>>
sequence(P1<Promise<A>> p)
          Traverses a product-1 inside a promise.
<A> Promise<Stream<A>>
sequence(Stream<Promise<A>> ps)
          Stream iteration inside a Promise.
<A> F<List<Promise<A>>,Promise<List<A>>>
sequenceList()
          A first-class function that traverses a list inside a promise.
<A> F<Stream<Promise<A>>,Promise<Stream<A>>>
sequenceStream()
          A first-class function that traverses a stream inside a promise.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

parModule

public static ParModule parModule(Strategy<Unit> u)
Constructor method for ParModule

Parameters:
u - A parallel strategy for the module.
Returns:
A ParModule that uses the given strategy for parallelism.

promise

public <A> Promise<A> promise(P1<A> p)
Evaluates the given product concurrently and returns a Promise of the result.

Parameters:
p - A product to evaluate concurrently.
Returns:
A Promise of the value of the given product, that can be claimed in the future.

promise

public <A> F<P1<A>,Promise<A>> promise()
Returns a function that evaluates a given product concurrently and returns a Promise of the result.

Returns:
a function that evaluates a given product concurrently and returns a Promise of the result.

promise

public <A,B> F<A,Promise<B>> promise(F<A,B> f)
Promotes the given function to a concurrent function that returns a Promise.

Parameters:
f - A given function to promote to a concurrent function.
Returns:
A function that is applied concurrently when given an argument, yielding a Promise of the result that can be claimed in the future.

promisePure

public <A,B> F<F<A,B>,F<A,Promise<B>>> promisePure()
Returns a function that promotes a given function to a concurrent function that returns a Promise. The pure Kleisli arrow of Promise.

Returns:
A higher-order function that takes pure functions to promise-valued functions.

promise

public <A,B,C> F2<A,B,Promise<C>> promise(F2<A,B,C> f)
Promotes the given function to a concurrent function that returns a Promise.

Parameters:
f - A given function to promote to a concurrent function.
Returns:
A function that is applied concurrently when given an argument, yielding a Promise of the result that can be claimed in the future.

effect

public <A> Actor<A> effect(Effect<A> e)
Creates a very fast concurrent effect, as an actor that does not guarantee ordering of its messages. Such an actor is not thread-safe unless the given Effect is.

Parameters:
e - The effect that the actor should have on its messages.
Returns:
A concurrent actor that does not guarantee ordering of its messages.

effect

public <A> F<Effect<A>,Actor<A>> effect()
A first-class constructor of concurrent effects, as actors that don't guarantee ordering of messages. Such an actor is not thread-safe unless the given Effect is.

Returns:
A function that takes an effect and returns a concurrent effect.

actor

public <A> QueueActor<A> actor(Effect<A> e)
Creates a concurrent actor that is guaranteed to process only one message at a time.

Parameters:
e - The effect that the actor should have on its messages.
Returns:
A concurrent actor that is guaranteed to process its messages in some order.

actor

public <A> F<Effect<A>,QueueActor<A>> actor()
A first-class constructor of actors.

Returns:
A function that takes an effect and returns an actor that processes messages in some order.

sequence

public <A> Promise<List<A>> sequence(List<Promise<A>> ps)
List iteration inside a Promise. Traverses a List of Promises yielding a Promise of a List.

Parameters:
ps - A list of promises to sequence.
Returns:
A promise of the List of values promised by the list of promises.

sequenceList

public <A> F<List<Promise<A>>,Promise<List<A>>> sequenceList()
A first-class function that traverses a list inside a promise.

Returns:
A first-class function that traverses a list inside a promise.

sequence

public <A> Promise<Stream<A>> sequence(Stream<Promise<A>> ps)
Stream iteration inside a Promise. Traverses a Stream of Promises yielding a Promise of a Stream.

Parameters:
ps - A Stream of promises to sequence.
Returns:
A promise of the Stream of values promised by the Stream of promises.

sequenceStream

public <A> F<Stream<Promise<A>>,Promise<Stream<A>>> sequenceStream()
A first-class function that traverses a stream inside a promise.

Returns:
A first-class function that traverses a stream inside a promise.

sequence

public <A> Promise<P1<A>> sequence(P1<Promise<A>> p)
Traverses a product-1 inside a promise.

Parameters:
p - A product-1 of a promised value.
Returns:
A promise of a product of the value promised by the argument.

mapM

public <A,B> Promise<List<B>> mapM(List<A> as,
                                   F<A,Promise<B>> f)
Takes a Promise-valued function and applies it to each element in the given List, yielding a promise of a List of results.

Parameters:
as - A list to map across.
f - A promise-valued function to map across the list.
Returns:
A Promise of a new list with the given function applied to each element.

mapList

public <A,B> F<F<A,Promise<B>>,F<List<A>,Promise<List<B>>>> mapList()
First-class function that maps a concurrent function over a List inside a promise.

Returns:
a function that maps a concurrent function over a List inside a promise.

mapM

public <A,B> Promise<Stream<B>> mapM(Stream<A> as,
                                     F<A,Promise<B>> f)
Takes a Promise-valued function and applies it to each element in the given Stream, yielding a promise of a Stream of results.

Parameters:
as - A Stream to map across.
f - A promise-valued function to map across the Stream.
Returns:
A Promise of a new Stream with the given function applied to each element.

mapStream

public <A,B> F<F<A,Promise<B>>,F<Stream<A>,Promise<Stream<B>>>> mapStream()
First-class function that maps a concurrent function over a Stream inside a promise.

Returns:
a function that maps a concurrent function over a Stream inside a promise.

mapM

public <A,B> Promise<P1<B>> mapM(P1<A> a,
                                 F<A,Promise<B>> f)
Maps a concurrent function over a Product-1 inside a Promise.

Parameters:
a - A product-1 across which to map.
f - A concurrent function to map over the product inside a promise.
Returns:
A promised product of the result of mapping the given function over the given product.

parMap

public <A,B> Promise<List<B>> parMap(List<A> as,
                                     F<A,B> f)
Maps across a list in parallel.

Parameters:
as - A list to map across in parallel.
f - A function to map across the given list.
Returns:
A Promise of a new list with the given function applied to each element.

parMapList

public <A,B> F<F<A,B>,F<List<A>,Promise<List<B>>>> parMapList()
A first-class function that maps another function across a list in parallel.

Returns:
A function that maps another function across a list in parallel.

parMap

public <A,B> Promise<NonEmptyList<B>> parMap(NonEmptyList<A> as,
                                             F<A,B> f)
Maps across a nonempty list in parallel.

Parameters:
as - A NonEmptyList to map across in parallel.
f - A function to map across the given NonEmptyList.
Returns:
A Promise of a new NonEmptyList with the given function applied to each element.

parMap

public <A,B> Promise<Stream<B>> parMap(Stream<A> as,
                                       F<A,B> f)
Maps across a Stream in parallel.

Parameters:
as - A Stream to map across in parallel.
f - A function to map across the given Stream.
Returns:
A Promise of a new Stream with the given function applied to each element.

parMapStream

public <A,B> F<F<A,B>,F<Stream<A>,Promise<Stream<B>>>> parMapStream()
A first-class function that maps another function across a stream in parallel.

Returns:
A function that maps another function across a stream in parallel.

parMap

public <A,B> Promise<Iterable<B>> parMap(Iterable<A> as,
                                         F<A,B> f)
Maps across an Iterable in parallel.

Parameters:
as - An Iterable to map across in parallel.
f - A function to map across the given Iterable.
Returns:
A Promise of a new Iterable with the given function applied to each element.

parMapIterable

public <A,B> F<F<A,B>,F<Iterable<A>,Promise<Iterable<B>>>> parMapIterable()
A first-class function that maps another function across an iterable in parallel.

Returns:
A function that maps another function across an iterable in parallel.

parMap

public <A,B> Promise<Array<B>> parMap(Array<A> as,
                                      F<A,B> f)
Maps across an Array in parallel.

Parameters:
as - An array to map across in parallel.
f - A function to map across the given Array.
Returns:
A Promise of a new Array with the given function applied to each element.

parMapArray

public <A,B> F<F<A,B>,F<Array<A>,Promise<Array<B>>>> parMapArray()
A first-class function that maps another function across an array in parallel.

Returns:
A function that maps another function across an array in parallel.

parMap

public <A,B> Promise<Zipper<B>> parMap(Zipper<A> za,
                                       F<A,B> f)
Maps a function across a Zipper in parallel.

Parameters:
za - A Zipper to map across in parallel.
f - A function to map across the given Zipper.
Returns:
A promise of a new Zipper with the given function applied to each element.

parMap

public <A,B> Promise<Tree<B>> parMap(Tree<A> ta,
                                     F<A,B> f)
Maps a function across a Tree in parallel.

Parameters:
ta - A Tree to map across in parallel.
f - A function to map across the given Tree.
Returns:
A promise of a new Tree with the given function applied to each element.

parMapTree

public <A,B> F<F<A,B>,F<Tree<A>,Promise<Tree<B>>>> parMapTree()
A first-class function that maps across a Tree in parallel.

Returns:
A function that maps a given function across a Tree in parallel.

parMap

public <A,B> Promise<TreeZipper<B>> parMap(TreeZipper<A> za,
                                           F<A,B> f)
Maps a function across a TreeZipper in parallel.

Parameters:
za - A TreeZipper to map across in parallel.
f - A function to map across the given TreeZipper.
Returns:
A promise of a new TreeZipper with the given function applied to each element of the tree.

parFlatMap

public <A,B> Promise<List<B>> parFlatMap(List<A> as,
                                         F<A,List<B>> f)
Binds a list-valued function across a list in parallel, concatenating the results into a new list.

Parameters:
as - A list to bind across in parallel.
f - A function to bind across the given list in parallel.
Returns:
A promise of a new List with the given function bound across its elements.

parFlatMap

public <A,B> Promise<Stream<B>> parFlatMap(Stream<A> as,
                                           F<A,Stream<B>> f)
Binds a Stream-valued function across a Stream in parallel, concatenating the results into a new Stream.

Parameters:
as - A Stream to bind across in parallel.
f - A function to bind across the given Stream in parallel.
Returns:
A promise of a new Stream with the given function bound across its elements.

parFlatMap

public <A,B> Promise<Array<B>> parFlatMap(Array<A> as,
                                          F<A,Array<B>> f)
Binds an Array-valued function across an Array in parallel, concatenating the results into a new Array.

Parameters:
as - An Array to bind across in parallel.
f - A function to bind across the given Array in parallel.
Returns:
A promise of a new Array with the given function bound across its elements.

parFlatMap

public <A,B> Promise<Iterable<B>> parFlatMap(Iterable<A> as,
                                             F<A,Iterable<B>> f)
Binds an Iterable-valued function across an Iterable in parallel, concatenating the results into a new Iterable.

Parameters:
as - A Iterable to bind across in parallel.
f - A function to bind across the given Iterable in parallel.
Returns:
A promise of a new Iterable with the given function bound across its elements.

parZipWith

public <A,B,C> Promise<List<C>> parZipWith(List<A> as,
                                           List<B> bs,
                                           F<A,F<B,C>> f)
Zips two lists together with a given function, in parallel.

Parameters:
as - A list to zip with another in parallel.
bs - A list to zip with another in parallel.
f - A function with which to zip two lists in parallel.
Returns:
A Promise of a new list with the results of applying the given function across the two lists in lockstep.

parZipWith

public <A,B,C> Promise<Stream<C>> parZipWith(Stream<A> as,
                                             Stream<B> bs,
                                             F<A,F<B,C>> f)
Zips two streams together with a given function, in parallel.

Parameters:
as - A stream to zip with another in parallel.
bs - A stream to zip with another in parallel.
f - A function with which to zip two streams in parallel.
Returns:
A Promise of a new stream with the results of applying the given function across the two streams, stepwise.

parZipWith

public <A,B,C> Promise<Array<C>> parZipWith(Array<A> as,
                                            Array<B> bs,
                                            F<A,F<B,C>> f)
Zips two arrays together with a given function, in parallel.

Parameters:
as - An array to zip with another in parallel.
bs - An array to zip with another in parallel.
f - A function with which to zip two arrays in parallel.
Returns:
A Promise of a new array with the results of applying the given function across the two arrays, stepwise.

parZipWith

public <A,B,C> Promise<Iterable<C>> parZipWith(Iterable<A> as,
                                               Iterable<B> bs,
                                               F<A,F<B,C>> f)
Zips two iterables together with a given function, in parallel.

Parameters:
as - An iterable to zip with another in parallel.
bs - An iterable to zip with another in parallel.
f - A function with which to zip two iterables in parallel.
Returns:
A Promise of a new iterable with the results of applying the given function across the two iterables, stepwise.

parFoldMap

public <A,B> Promise<B> parFoldMap(Stream<A> as,
                                   F<A,B> map,
                                   Monoid<B> reduce)
Maps with the given function across the given stream in parallel, while folding with the given monoid.

Parameters:
as - A stream to map over and reduce.
map - The function to map over the given stream.
reduce - The monoid with which to sum the results.
Returns:
A promise of a result of mapping and folding in parallel.

parFoldMap

public <A,B> Promise<B> parFoldMap(Stream<A> as,
                                   F<A,B> map,
                                   Monoid<B> reduce,
                                   F<Stream<A>,P2<Stream<A>,Stream<A>>> chunking)
Maps with the given function across chunks of the given stream in parallel, while folding with the given monoid. The stream is split into chunks according to the given chunking function, the given map function is mapped over all chunks simultaneously, but over each chunk sequentially. All chunks are summed concurrently and the sums are then summed sequentially.

Parameters:
as - A stream to chunk, then map over and reduce.
map - The function to map over the given stream.
reduce - The monoid with which to sum the results.
chunking - A function describing how the stream should be split into chunks. Should return the first chunk and the rest of the stream.
Returns:
A promise of a result of mapping and folding in parallel.

parFoldMap

public <A,B> Promise<B> parFoldMap(Iterable<A> as,
                                   F<A,B> map,
                                   Monoid<B> reduce,
                                   F<Iterable<A>,P2<Iterable<A>,Iterable<A>>> chunking)
Maps with the given function across chunks of the given Iterable in parallel, while folding with the given monoid. The Iterable is split into chunks according to the given chunking function, the given map function is mapped over all chunks simultaneously, but over each chunk sequentially. All chunks are summed concurrently and the sums are then summed sequentially.

Parameters:
as - An Iterable to chunk, then map over and reduce.
map - The function to map over the given Iterable.
reduce - The monoid with which to sum the results.
chunking - A function describing how the Iterable should be split into chunks. Should return the first chunk and the rest of the Iterable.
Returns:
A promise of a result of mapping and folding in parallel.

parFoldMap

public <A,B> Promise<B> parFoldMap(Iterable<A> as,
                                   F<A,B> map,
                                   Monoid<B> reduce)
Maps with the given function across the given iterable in parallel, while folding with the given monoid.

Parameters:
as - An Iterable to map over and reduce.
map - The function to map over the given Iterable.
reduce - The Monoid with which to sum the results.
Returns:
A promise of a result of mapping and folding in parallel.

parExtend

public <A,B> Promise<Zipper<B>> parExtend(Zipper<A> za,
                                          F<Zipper<A>,B> f)
Maps the given function across all positions of the given zipper in parallel.

Parameters:
za - A zipper to extend the given function across.
f - A function to extend across the given zipper.
Returns:
A promise of a new zipper of the results of applying the given function to all positions of the given zipper.

parExtend

public <A,B> Promise<Tree<B>> parExtend(Tree<A> ta,
                                        F<Tree<A>,B> f)
Maps the given function across all subtrees of the given Tree in parallel.

Parameters:
ta - A tree to extend the given function across.
f - A function to extend across the given Tree.
Returns:
A promise of a new Tree of the results of applying the given function to all subtrees of the given Tree.

parExtend

public <A,B> Promise<TreeZipper<B>> parExtend(TreeZipper<A> za,
                                              F<TreeZipper<A>,B> f)
Maps the given function across all positions of the given TreeZipper in parallel.

Parameters:
za - A TreeZipper to extend the given function across.
f - A function to extend across the given TreeZipper.
Returns:
A promise of a new TreeZipper of the results of applying the given function to all positions of the given TreeZipper.

parExtend

public <A,B> Promise<NonEmptyList<B>> parExtend(NonEmptyList<A> as,
                                                F<NonEmptyList<A>,B> f)
Maps the given function across all sublists of the given NonEmptyList in parallel.

Parameters:
as - A NonEmptyList to extend the given function across.
f - A function to extend across the given NonEmptyList
Returns:
A promise of a new NonEmptyList of the results of applying the given function to all sublists of the given NonEmptyList.

Copyright 2008 - 2009 Tony Morris, Runar Bjarnason, Tom Adams, Brad Clow, Ricky Clarkson, Nick Partridge, Jason Zaugg

This software is released under an open source BSD licence.