Back to Fpinscala

01.Answer

answerkey/parallelism/01.answer.md

latest504 B
Original Source
scala
/* As an extension method: */
extension [A](pa: Par[A]) def map2[B, C](pb: Par[B])(f: (A, B) => C): Par[C] = // `map2` doesn't evaluate the call to `f` in a separate logical thread, in accord with our design choice of having `fork` be the sole function in the API for controlling parallelism. We can always do `fork(map2(a,b)(f))` if we want the evaluation of `f` to occur in a separate thread.

/* As a standalone function: */
def map2[A, B, C](a: Par[A], b: Par[B])(f: (A, B) => C): Par[C]