Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Parallel.apply overload with one type parameter #3031

Merged
merged 1 commit into from
Sep 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions core/src/main/scala/cats/Parallel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,14 @@ object NonEmptyParallel {
type Aux[M[_], F0[_]] = NonEmptyParallel[M] { type F[x] = F0[x] }

def apply[M[_], F[_]](implicit P: NonEmptyParallel.Aux[M, F]): NonEmptyParallel.Aux[M, F] = P
def apply[M[_]](implicit P: NonEmptyParallel[M], D: DummyImplicit): NonEmptyParallel.Aux[M, P.F] = P
}

object Parallel extends ParallelArityFunctions2 {
type Aux[M[_], F0[_]] = Parallel[M] { type F[x] = F0[x] }

def apply[M[_], F[_]](implicit P: Parallel.Aux[M, F]): Parallel.Aux[M, F] = P
def apply[M[_]](implicit P: Parallel[M], D: DummyImplicit): Parallel.Aux[M, P.F] = P

/**
* Like `Traverse[A].sequence`, but uses the applicative instance
Expand Down
20 changes: 20 additions & 0 deletions tests/src/test/scala/cats/tests/ParallelSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,26 @@ class ParallelSuite extends CatsSuite with ApplicativeErrorForEitherTest with Sc
)
}

test("NonEmptyParallel.apply should return an appropriately typed instance given both type parameters") {
val p1: NonEmptyParallel.Aux[Either[String, *], Validated[String, *]] =
NonEmptyParallel[Either[String, *], Validated[String, *]]
val p2: NonEmptyParallel.Aux[NonEmptyList, ZipNonEmptyList] = NonEmptyParallel[NonEmptyList, ZipNonEmptyList]
}

test("NonEmptyParallel.apply should return an appropriately typed instance given the first type parameter") {
val p1: NonEmptyParallel.Aux[Either[String, *], Validated[String, *]] = NonEmptyParallel[Either[String, *]]
val p2: NonEmptyParallel.Aux[NonEmptyList, ZipNonEmptyList] = NonEmptyParallel[NonEmptyList]
}

test("Parallel.apply should return an appropriately typed instance given both type parameters") {
val p1: Parallel.Aux[Either[String, *], Validated[String, *]] = Parallel[Either[String, *], Validated[String, *]]
val p2: Parallel.Aux[Stream, ZipStream] = Parallel[Stream, ZipStream]
}

test("Parallel.apply should return an appropriately typed instance given the first type parameter") {
val p1: Parallel.Aux[Either[String, *], Validated[String, *]] = Parallel[Either[String, *], Validated[String, *]]
val p2: Parallel.Aux[Stream, ZipStream] = Parallel[Stream]
}
}

trait ApplicativeErrorForEitherTest extends AnyFunSuiteLike with Discipline {
Expand Down