Add coursier.util.Gather

This commit is contained in:
Alexandre Archambault 2018-02-27 22:54:48 +01:00
parent 5e1eeef757
commit c037dbaeeb
2 changed files with 21 additions and 4 deletions

View File

@ -1,9 +1,8 @@
package coursier package coursier
import coursier.util.{EitherT, Monad} import coursier.util.{EitherT, Gather, Monad}
import scala.language.higherKinds import scala.language.higherKinds
import scalaz.Nondeterminism
object Fetch { object Fetch {
@ -59,12 +58,12 @@ object Fetch {
fetch: Content[F], fetch: Content[F],
extra: Content[F]* extra: Content[F]*
)(implicit )(implicit
F: Nondeterminism[F] F: Gather[F]
): Metadata[F] = { ): Metadata[F] = {
modVers => modVers =>
F.map( F.map(
F.gatherUnordered { F.gather {
modVers.map { modVers.map {
case (module, version) => case (module, version) =>
def get(fetch: Content[F]) = find(repositories, module, version, fetch) def get(fetch: Content[F]) = find(repositories, module, version, fetch)

View File

@ -0,0 +1,18 @@
package coursier.util
import scala.language.higherKinds
trait Gather[F[_]] extends Monad[F] {
def gather[A](elems: Seq[F[A]]): F[Seq[A]]
}
object Gather {
implicit def fromScalaz[F[_]](implicit N: scalaz.Nondeterminism[F]): Gather[F] =
new Gather[F] {
def point[A](a: A) = N.pure(a)
def bind[A, B](elem: F[A])(f: A => F[B]) = N.bind(elem)(f)
def gather[A](elems: Seq[F[A]]) = N.map(N.gather(elems))(l => l)
}
}