Skip to content

Commit

Permalink
add Nondeterminism#parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
xuwei-k committed Jul 24, 2015
1 parent 1164a0b commit c5dc848
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/scalaz/Nondeterminism.scala
Expand Up @@ -15,6 +15,7 @@ package scalaz
trait Nondeterminism[F[_]] extends Monad[F] { self =>
////

import scalaz.Tags.Parallel
import scalaz.std.anyVal._

/**
Expand Down Expand Up @@ -177,6 +178,15 @@ trait Nondeterminism[F[_]] extends Monad[F] { self =>
def aggregateCommutative1[A: Semigroup](fs: NonEmptyList[F[A]]): F[A] =
map(gatherUnordered1(fs))(Foldable1[NonEmptyList].suml1(_))

def parallel: Applicative[λ[α => F[α] @@ Parallel]] =
new Applicative[λ[α => F[α] @@ Parallel]] {
def point[A](a: => A) = Parallel(self.point(a))
override def map[A, B](fa: F[A] @@ Parallel)(f: A => B) =
Parallel(self.map(Tag.unwrap(fa))(f))
def ap[A, B](fa: => F[A] @@ Parallel)(fab: => F[A => B] @@ Parallel) =
Parallel(self.mapBoth(Tag.unwrap(fa), Tag.unwrap(fab))((a, f) => f(a)))
}

////
val nondeterminismSyntax = new scalaz.syntax.NondeterminismSyntax[F] { def F = Nondeterminism.this }
}
Expand Down

0 comments on commit c5dc848

Please sign in to comment.