-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 more Parallel instances #1938
Merged
Merged
Changes from 78 commits
Commits
Show all changes
80 commits
Select commit
Hold shift + click to select a range
eaf34e6
Initial version of Parallel
21942c5
Add Either/Validated Parallel instance
b37732b
Break up syntax for parallel
664988a
Add Parallel syntax tests
e7f6f68
Add Tuple syntax for Parallel
f37500a
Add ParallelTests
447d929
Fix Parallel law
4259554
Add more tests
6c5efc9
Add Parallel Kleisli instance
d7ba338
Add instances for OptionT and EitherT to nested
a7bea82
Add law tests for parallel OptionT and EitherT
1556909
Make EitherT instance forward to Validated
b3470db
Add Kleisli lawTest
b458b3d
Add WriterT instance
2815a5b
Add more tests
7844788
Add scaladoc
378549f
Add ApplicativeError instance for MonadError and Parallel
1490fe4
Add Test that actually hits the implicated ApplicativeError instance
2dc71fe
Fix mixup
00664ae
Move appError instance to Parallel companion object
f941a0c
Fix apperror test
1236205
Add sequential roundtrip law
17c0bc0
Add ZipNEL and ZipNEV and Parallel instances
1502087
Add law for testing that pure is consistent across Parallel pairs
f1b1c1a
Add Parallel Serializable tests
9252e36
Add EitherT Parallel instance that doesn't require a Parallel Instanc…
e8eb35d
Add ZipVector + Parallel instance
1a99aab
Add ZipVector test
ae03b33
Add scaladoc to ApplicativeError and change order of type parameters
11caba0
Add Parallel#identity function
1027a41
Add identity instances for Future and Id
942a152
Simplify parAp2 implementation
6354e08
Refactor Parallel
26b7930
Add applicativeError instace method
9e3891d
Reverse applicativeError and remove redundant .apply
4dbc995
Simplify further
61b7cc7
Add FailFastFuture + Parallel instance
50c5732
Shorten wait times
c661860
Add ZipStream and OneAnd instance
ccc5f45
Convert traits to abstract classes
3a300b4
Merge branch 'master' into add-parallel-class
ecc8e50
Add consistency test for zip stream
4882401
Add Applicative test for Applicative[OneAnd]
50c9619
Add parAp test
db973c9
Add ZipList and lawtest all Zip* instances
615a1a5
Add ZipList consistency test
7395c0a
Add NonEmptyParallel
a8afdfe
Add test cases for ParNonEmptyTraverse
7f91072
Update scaladoc
c5e3423
Remove FailFastFuture and all Zip* instances
15d9a45
Rename methods in NonEmptyParallel
ad8a7c4
optimize AppError
71a1239
Add parFlatTraverse and sequence
eb274cf
Revert "Remove FailFastFuture and all Zip* instances"
4151e7e
Add parFlatTraverse and sequence
87f7b87
Merge branch 'master' into add-parallel-class
c956900
Merge branch 'add-parallel-class' into parallel-zip-instances
4a9f2ad
Add isomorphic functor law
e7f659e
Merge branch 'add-parallel-class' into parallel-zip-instances
17acb6f
Add ZipMap?
7a6cd52
Fix law test parameters
c67c953
Merge branch 'add-parallel-class' into parallel-zip-instances
cca85ea
Merge branch 'master' into add-parallel-class
ddb2457
Merge branch 'add-parallel-class' into parallel-zip-instances
8dcfc4a
Merge branch 'master' into add-parallel-class
bcad984
Merge branch 'add-parallel-class' into parallel-zip-instances
782d568
Remove ZipMap
4bbd46e
Merge branch 'master' into add-parallel-class
0c87a1b
Merge branch 'master' into add-parallel-class
e9ab6b4
Merge branch 'add-parallel-class' into parallel-zip-instances
7074f8f
Merge branch 'master' into parallel-zip-instances
d1eeb55
Fix the priority of OneAnd instances
9114b2a
Rename Parallel tests
8bfec4b
Rename Parallel tests
5f6ef8c
Merge branch 'parallel-zip-instances' of https://github.com/LukaJCB/c…
6c22f90
Merge branch 'master' into parallel-zip-instances
0e752e3
Add mima exceptions
2ca66c9
Remove fail fast future
c92a34a
Merge branch 'master' into parallel-zip-instances
15def60
Merge branch 'master' into parallel-zip-instances
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cats.data | ||
|
||
import cats.{CommutativeApply, Eq} | ||
import cats.instances.list.catsKernelStdEqForList | ||
|
||
class ZipList[A](val value: List[A]) extends AnyVal | ||
|
||
object ZipList { | ||
|
||
def apply[A](value: List[A]): ZipList[A] = new ZipList(value) | ||
|
||
implicit val catsDataCommutativeApplyForZipList: CommutativeApply[ZipList] = new CommutativeApply[ZipList] { | ||
|
||
override def map[A, B](fa: ZipList[A])(f: (A) => B): ZipList[B] = | ||
ZipList(fa.value.map(f)) | ||
|
||
def ap[A, B](ff: ZipList[A => B])(fa: ZipList[A]): ZipList[B] = | ||
ZipList((ff.value, fa.value).zipped.map(_ apply _)) | ||
|
||
override def product[A, B](fa: ZipList[A], fb: ZipList[B]): ZipList[(A, B)] = | ||
ZipList(fa.value.zip(fb.value)) | ||
|
||
} | ||
|
||
implicit def catsDataEqForZipList[A: Eq]: Eq[ZipList[A]] = Eq.by(_.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package cats.data | ||
|
||
import cats.{Alternative, CommutativeApplicative, Eq} | ||
import cats.instances.stream._ | ||
|
||
class ZipStream[A](val value: Stream[A]) extends AnyVal | ||
|
||
object ZipStream { | ||
|
||
def apply[A](value: Stream[A]): ZipStream[A] = new ZipStream(value) | ||
|
||
implicit val catsDataAlternativeForZipStream: Alternative[ZipStream] with CommutativeApplicative[ZipStream] = | ||
new Alternative[ZipStream] with CommutativeApplicative[ZipStream] { | ||
def pure[A](x: A): ZipStream[A] = new ZipStream(Stream.continually(x)) | ||
|
||
override def map[A, B](fa: ZipStream[A])(f: (A) => B): ZipStream[B] = | ||
ZipStream(fa.value.map(f)) | ||
|
||
def ap[A, B](ff: ZipStream[A => B])(fa: ZipStream[A]): ZipStream[B] = | ||
ZipStream((ff.value, fa.value).zipped.map(_ apply _)) | ||
|
||
override def product[A, B](fa: ZipStream[A], fb: ZipStream[B]): ZipStream[(A, B)] = | ||
ZipStream(fa.value.zip(fb.value)) | ||
|
||
def empty[A]: ZipStream[A] = ZipStream(Stream.empty[A]) | ||
|
||
def combineK[A](x: ZipStream[A], y: ZipStream[A]): ZipStream[A] = | ||
ZipStream(Alternative[Stream].combineK(x.value, y.value)) | ||
} | ||
|
||
implicit def catsDataEqForZipStream[A: Eq]: Eq[ZipStream[A]] = Eq.by(_.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cats.data | ||
|
||
import cats.{CommutativeApply, Eq} | ||
import cats.instances.vector._ | ||
|
||
class ZipVector[A](val value: Vector[A]) extends AnyVal | ||
|
||
object ZipVector { | ||
|
||
def apply[A](value: Vector[A]): ZipVector[A] = new ZipVector(value) | ||
|
||
implicit val catsDataCommutativeApplyForZipVector: CommutativeApply[ZipVector] = new CommutativeApply[ZipVector] { | ||
|
||
override def map[A, B](fa: ZipVector[A])(f: (A) => B): ZipVector[B] = | ||
ZipVector(fa.value.map(f)) | ||
def ap[A, B](ff: ZipVector[A => B])(fa: ZipVector[A]): ZipVector[B] = | ||
ZipVector((ff.value, fa.value).zipped.map(_ apply _)) | ||
|
||
} | ||
|
||
implicit def catsDataEqForZipVector[A: Eq]: Eq[ZipVector[A]] = Eq.by(_.value) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ package cats.instances | |
import cats.data._ | ||
import cats.kernel.Semigroup | ||
import cats.syntax.either._ | ||
import cats.{Applicative, Functor, Monad, Parallel, ~>} | ||
import cats.{Applicative, Apply, FlatMap, Functor, Monad, NonEmptyParallel, Parallel, ~>} | ||
|
||
|
||
trait ParallelInstances extends ParallelInstances1 { | ||
implicit def catsParallelForEitherValidated[E: Semigroup]: Parallel[Either[E, ?], Validated[E, ?]] = new Parallel[Either[E, ?], Validated[E, ?]] { | ||
|
@@ -36,6 +37,45 @@ trait ParallelInstances extends ParallelInstances1 { | |
λ[OptionT[M, ?] ~> Nested[F, Option, ?]](optT => Nested(P.parallel(optT.value))) | ||
} | ||
|
||
implicit def catsStdNonEmptyParallelForZipList[A]: NonEmptyParallel[List, ZipList] = | ||
new NonEmptyParallel[List, ZipList] { | ||
|
||
def flatMap: FlatMap[List] = cats.instances.list.catsStdInstancesForList | ||
def apply: Apply[ZipList] = ZipList.catsDataCommutativeApplyForZipList | ||
|
||
def sequential: ZipList ~> List = | ||
λ[ZipList ~> List](_.value) | ||
|
||
def parallel: List ~> ZipList = | ||
λ[List ~> ZipList](v => new ZipList(v)) | ||
} | ||
|
||
implicit def catsStdNonEmptyParallelForZipVector[A]: NonEmptyParallel[Vector, ZipVector] = | ||
new NonEmptyParallel[Vector, ZipVector] { | ||
|
||
def flatMap: FlatMap[Vector] = cats.instances.vector.catsStdInstancesForVector | ||
def apply: Apply[ZipVector] = ZipVector.catsDataCommutativeApplyForZipVector | ||
|
||
def sequential: ZipVector ~> Vector = | ||
λ[ZipVector ~> Vector](_.value) | ||
|
||
def parallel: Vector ~> ZipVector = | ||
λ[Vector ~> ZipVector](v => new ZipVector(v)) | ||
} | ||
|
||
implicit def catsStdParallelForZipStream[A]: Parallel[Stream, ZipStream] = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same idea as above, if we can't test it, maybe moving to alleycats? |
||
new Parallel[Stream, ZipStream] { | ||
|
||
def monad: Monad[Stream] = cats.instances.stream.catsStdInstancesForStream | ||
def applicative: Applicative[ZipStream] = ZipStream.catsDataAlternativeForZipStream | ||
|
||
def sequential: ZipStream ~> Stream = | ||
λ[ZipStream ~> Stream](_.value) | ||
|
||
def parallel: Stream ~> ZipStream = | ||
λ[Stream ~> ZipStream](v => new ZipStream(v)) | ||
} | ||
|
||
|
||
implicit def catsParallelForEitherTNestedParallelValidated[F[_], M[_], E: Semigroup] | ||
(implicit P: Parallel[M, F]): Parallel[EitherT[M, E, ?], Nested[F, Validated[E, ?], ?]] = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be lawful right? but we can't test it...that's awkward. how about moving it to alleycats?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awkward indeed, I'm not sure if alleycats is the right place, since they can be proven to be lawful in e.g. Haskell, but I agree that it's awkward.
Maybe we should move the
CommutativeApplicative
instance to Alleycats and keep theCommutativeApply
instance here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about that but it would cause implicit conflict if you import both right? Unless we do the export hook trick which is kind of deprecated. Maybe we just document a bit more.