choiceMap selects a parallel computation from a Map using the result of an initial parallel computation. It first runs key, waits for the resulting key, looks up choices(k), and runs the selected Par.
The combinator illustrates a progression from specialized selection to a general data-dependent computation:
- choice handles a Boolean by selecting between two computations. section 7.4
- choiceMap replaces indexed lookup with key-based lookup, while still requiring only a function from the initial result to the next computation. section 7.4
Map-directed execution
def choiceMap[K, V](key: Par[K])(choices: Map[K, Par[V]]): Par[V] = es => val k = key.run(es).get choices(k).run
