-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
WIP: Selective #3709
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
Closed
Closed
WIP: Selective #3709
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
444e3bd
Introduce Selective
rossabaker da7f756
Split into Select and Selective
rossabaker d220349
Selective[Validated[E, *]]
rossabaker 4c7f87e
SelectiveError
rossabaker 14d3e42
FlatMap extends Select
rossabaker f554862
Merge branch 'master' into selective
rossabaker b7112ac
Required parens on lambda
rossabaker b8dc63b
Default select from Apply until Monad
rossabaker 7fd409b
Start writing SelectiveLaws
rossabaker 254bf7f
Look at me, not compiling before I push
rossabaker ed71f06
Never mind on Select
rossabaker 7767906
branch, ifS, whenS
rossabaker 466354b
select is an abstract member of Selective
rossabaker f31020a
Law for monad select rigidity
rossabaker 4a2b0be
scalafmt
rossabaker 955a03b
Use our new syntax
rossabaker e35a097
Test default operations
rossabaker df699d1
Derive missing implicits for selective laws
rossabaker a50da48
Remove SelectiveError for now
rossabaker 387ab75
Selective distributivity and associativity
rossabaker cb51502
Clean up syntax
rossabaker 06abe62
apS and RigidSelective laws
rossabaker 9b001dd
Remove inner scope in branch
rossabaker 19b67b4
Move EitherUtil to root package for use in typeclasses
rossabaker 662cf5a
Use cached either units in ifS
rossabaker 936847f
Fix loop in laws inheritance
rossabaker 3372948
Remove unnecessary private[cats] in EitherUtil
rossabaker a866a20
Apply.selectA
rossabaker 260a219
select's function is lazy; skip on right law for rigids
rossabaker a0f8709
Skip effects in branch and ifS in rigid selectives
rossabaker 37594b9
Skip effect of whenS when false in rigid selectives
rossabaker b56130d
Replace apS with RigidSelective typeclass
rossabaker 9079e16
Validated is rigid
rossabaker 020a9fb
Revert "Validated is rigid" -- it's not rigid yet
rossabaker 92f262f
Push select down to Apply
rossabaker 762dd7d
Push branch and ifS down to Apply
rossabaker 691144e
Push whenS down to Applicative
rossabaker 3e31609
Push identity and distributivity laws to Applicative
rossabaker 6b496ec
Remove Selective
rossabaker acce38c
Remove commented implicits
rossabaker 7c78d54
RigidSelective default ap causes loops
rossabaker c4c1442
Add back lost selective associativity test
rossabaker 3bcb791
Restate ifS skip laws to accommodate Under
rossabaker dba3dc0
Selective has re-entered the chat
rossabaker 7a4d66a
Selective[ZipLazyList]
rossabaker 6616707
Selective[Func] and RigidSelective[Func]
rossabaker bd0d4d9
Fix name of selective laws
rossabaker 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,14 @@ | ||
| package cats | ||
|
|
||
| /** | ||
| * Convenience methods and values for Either. | ||
| */ | ||
| private[cats] object EitherUtil { | ||
| def leftCast[A, B, C](right: Right[A, B]): Either[C, B] = | ||
| right.asInstanceOf[Either[C, B]] | ||
| def rightCast[A, B, C](left: Left[A, B]): Either[A, C] = | ||
| left.asInstanceOf[Either[A, C]] | ||
|
|
||
| val unit = Right(()) | ||
| val leftUnit = Left(()) | ||
| } |
This file contains hidden or 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 hidden or 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,53 @@ | ||
| package cats | ||
|
|
||
| import simulacrum.typeclass | ||
| import scala.annotation.implicitNotFound | ||
|
|
||
| @implicitNotFound("Could not find an instance of RigidSelective for ${F}") | ||
| @typeclass trait RigidSelective[F[_]] extends Selective[F] | ||
|
|
||
| object RigidSelective { | ||
| /* ======================================================================== */ | ||
| /* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */ | ||
| /* ======================================================================== */ | ||
|
|
||
| /** | ||
| * Summon an instance of [[RigidSelective]] for `F`. | ||
| */ | ||
| @inline def apply[F[_]](implicit instance: RigidSelective[F]): RigidSelective[F] = instance | ||
|
|
||
| @deprecated("Use cats.syntax object imports", "2.2.0") | ||
| object ops { | ||
| implicit def toAllRigidSelectiveOps[F[_], A](target: F[A])(implicit tc: RigidSelective[F]): AllOps[F, A] { | ||
| type TypeClassType = RigidSelective[F] | ||
| } = new AllOps[F, A] { | ||
| type TypeClassType = RigidSelective[F] | ||
| val self: F[A] = target | ||
| val typeClassInstance: TypeClassType = tc | ||
| } | ||
| } | ||
| trait Ops[F[_], A] extends Serializable { | ||
| type TypeClassType <: RigidSelective[F] | ||
| def self: F[A] | ||
| val typeClassInstance: TypeClassType | ||
| } | ||
| trait AllOps[F[_], A] extends Ops[F, A] with Selective.AllOps[F, A] { | ||
| type TypeClassType <: RigidSelective[F] | ||
| } | ||
| trait ToRigidSelectiveOps extends Serializable { | ||
| implicit def toRigidSelectiveOps[F[_], A](target: F[A])(implicit tc: RigidSelective[F]): Ops[F, A] { | ||
| type TypeClassType = RigidSelective[F] | ||
| } = new Ops[F, A] { | ||
| type TypeClassType = RigidSelective[F] | ||
| val self: F[A] = target | ||
| val typeClassInstance: TypeClassType = tc | ||
| } | ||
| } | ||
| @deprecated("Use cats.syntax object imports", "2.2.0") | ||
| object nonInheritedOps extends ToRigidSelectiveOps | ||
|
|
||
| /* ======================================================================== */ | ||
| /* END OF SIMULACRUM-MANAGED CODE */ | ||
| /* ======================================================================== */ | ||
|
|
||
| } |
This file contains hidden or 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,66 @@ | ||
| package cats | ||
|
|
||
| import simulacrum.typeclass | ||
| import scala.annotation.implicitNotFound | ||
|
|
||
| @implicitNotFound("Could not find an instance of Selective for ${F}") | ||
| @typeclass trait Selective[F[_]] extends Applicative[F] { | ||
| def select[A, B](fab: F[Either[A, B]])(ff: => F[A => B]): F[B] | ||
|
|
||
| def branch[A, B, C](fab: F[Either[A, B]])(fl: => F[A => C])(fr: => F[B => C]): F[C] = { | ||
| val innerLhs: F[Either[A, Either[B, C]]] = map(fab)(_.map(Left(_))) | ||
| def innerRhs: F[A => Either[B, C]] = map(fl)(_.andThen(Right(_))) | ||
| val lhs = select(innerLhs)(innerRhs) | ||
| select(lhs)(fr) | ||
| } | ||
| } | ||
|
|
||
| object Selective { | ||
| /* ======================================================================== */ | ||
| /* THE FOLLOWING CODE IS MANAGED BY SIMULACRUM; PLEASE DO NOT EDIT!!!! */ | ||
| /* ======================================================================== */ | ||
|
|
||
| /** | ||
| * Summon an instance of [[Selective]] for `F`. | ||
| */ | ||
| @inline def apply[F[_]](implicit instance: Selective[F]): Selective[F] = instance | ||
|
|
||
| @deprecated("Use cats.syntax object imports", "2.2.0") | ||
| object ops { | ||
| implicit def toAllSelectiveOps[F[_], A](target: F[A])(implicit tc: Selective[F]): AllOps[F, A] { | ||
| type TypeClassType = Selective[F] | ||
| } = new AllOps[F, A] { | ||
| type TypeClassType = Selective[F] | ||
| val self: F[A] = target | ||
| val typeClassInstance: TypeClassType = tc | ||
| } | ||
| } | ||
| trait Ops[F[_], A] extends Serializable { | ||
| type TypeClassType <: Selective[F] | ||
| def self: F[A] | ||
| val typeClassInstance: TypeClassType | ||
| def select[B, C](ff: => F[B => C])(implicit ev$1: A <:< Either[B, C]): F[C] = | ||
| typeClassInstance.select[B, C](self.asInstanceOf[F[Either[B, C]]])(ff) | ||
| def branch[B, C, D](fl: => F[B => D])(fr: => F[C => D])(implicit ev$1: A <:< Either[B, C]): F[D] = | ||
| typeClassInstance.branch[B, C, D](self.asInstanceOf[F[Either[B, C]]])(fl)(fr) | ||
| } | ||
| trait AllOps[F[_], A] extends Ops[F, A] with Applicative.AllOps[F, A] { | ||
| type TypeClassType <: Selective[F] | ||
| } | ||
| trait ToSelectiveOps extends Serializable { | ||
| implicit def toSelectiveOps[F[_], A](target: F[A])(implicit tc: Selective[F]): Ops[F, A] { | ||
| type TypeClassType = Selective[F] | ||
| } = new Ops[F, A] { | ||
| type TypeClassType = Selective[F] | ||
| val self: F[A] = target | ||
| val typeClassInstance: TypeClassType = tc | ||
| } | ||
| } | ||
| @deprecated("Use cats.syntax object imports", "2.2.0") | ||
| object nonInheritedOps extends ToSelectiveOps | ||
|
|
||
| /* ======================================================================== */ | ||
| /* END OF SIMULACRUM-MANAGED CODE */ | ||
| /* ======================================================================== */ | ||
|
|
||
| } | ||
This file contains hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.