From c037dbaeebb2b00bff7f41e583b5ee5e85eff4bf Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Tue, 27 Feb 2018 22:54:48 +0100 Subject: [PATCH] Add coursier.util.Gather --- .../shared/src/main/scala/coursier/Fetch.scala | 7 +++---- .../src/main/scala/coursier/util/Gather.scala | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 core/shared/src/main/scala/coursier/util/Gather.scala diff --git a/core/shared/src/main/scala/coursier/Fetch.scala b/core/shared/src/main/scala/coursier/Fetch.scala index 36fe18a46..866e9b9a3 100644 --- a/core/shared/src/main/scala/coursier/Fetch.scala +++ b/core/shared/src/main/scala/coursier/Fetch.scala @@ -1,9 +1,8 @@ package coursier -import coursier.util.{EitherT, Monad} +import coursier.util.{EitherT, Gather, Monad} import scala.language.higherKinds -import scalaz.Nondeterminism object Fetch { @@ -59,12 +58,12 @@ object Fetch { fetch: Content[F], extra: Content[F]* )(implicit - F: Nondeterminism[F] + F: Gather[F] ): Metadata[F] = { modVers => F.map( - F.gatherUnordered { + F.gather { modVers.map { case (module, version) => def get(fetch: Content[F]) = find(repositories, module, version, fetch) diff --git a/core/shared/src/main/scala/coursier/util/Gather.scala b/core/shared/src/main/scala/coursier/util/Gather.scala new file mode 100644 index 000000000..0da299040 --- /dev/null +++ b/core/shared/src/main/scala/coursier/util/Gather.scala @@ -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) + } + +}