-
-
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
Drop noop for Functor unzip with Liskov evidence #3318
Merged
Merged
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
3f19e23
Drop noop for Functor unzip with Liskov evidence
yangzai 35a5f97
Overload unzip for bin compat
yangzai 1cac349
Make type params explicit
yangzai 999f735
Backport unzip method in functor typeclass for scala_2.11 (#3234)
gagandeepkalra 08c1ad8
Clean up cherry-picked forwardport
yangzai 47312b4
Replace UnzipFunctorOps with FunctorOps0 with Liskov based unzip impl…
yangzai da2980f
Merge branch 'master' into hy-unzip-liskov
yangzai ffcaac1
Drop bincompat traits and numerical suffixes, move implicit conversio…
yangzai aff4a51
Refactored unzip
yangzai ce88554
Merge branch 'master' into hy-unzip-liskov
yangzai 052ee9c
Fix formatting
yangzai 059ec70
Add missing assertions and rewrite unzip compilation test for munit
yangzai 295d9ad
Reimplement Functor unzip (together with other helpful methods) as Tu…
yangzai 2e9d877
Switch NEL to List, not testing unzip here
yangzai c298b7e
Switch Id to Option for doctests
yangzai 49ad8b1
Fix test name grammar
yangzai 3a6b1f2
Switch to `Chain` as `Option#unzip` already defined in Scala 2.13
yangzai 22b52e2
Merge branch 'master' into hy-unzip-liskov
larsrh 79b6f06
Update tests/src/test/scala/cats/tests/FunctorSuite.scala
larsrh 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,64 @@ | ||
package cats | ||
package syntax | ||
|
||
trait FunctorSyntax extends Functor.ToFunctorOps | ||
trait FunctorSyntax extends Functor.ToFunctorOps { | ||
implicit final def catsSyntaxFunctorTuple2Ops[F[_], A, B](fab: F[(A, B)]): FunctorTuple2Ops[F, A, B] = | ||
new FunctorTuple2Ops[F, A, B](fab) | ||
} | ||
|
||
final class FunctorTuple2Ops[F[_], A, B](private val fab: F[(A, B)]) extends AnyVal { | ||
|
||
/** | ||
* Lifts `Tuple2#_1` to Functor | ||
* | ||
* {{{ | ||
* scala> import cats.Id | ||
* scala> import cats.syntax.functor._ | ||
* | ||
* scala> ((1, 2): Id[(Int, Int)])._1F == 1 | ||
* res0: Boolean = true | ||
* }}} | ||
*/ | ||
def _1F(implicit F: Functor[F]): F[A] = F.map(fab)(_._1) | ||
|
||
/** | ||
* Lifts `Tuple2#_2` to Functor | ||
* | ||
* {{{ | ||
* scala> import cats.Id | ||
* scala> import cats.syntax.functor._ | ||
* | ||
* scala> ((1, 2): Id[(Int, Int)])._2F == 2 | ||
* res0: Boolean = true | ||
* }}} | ||
*/ | ||
def _2F(implicit F: Functor[F]): F[B] = F.map(fab)(_._2) | ||
|
||
/** | ||
* Lifts `Tuple2#swap` to Functor | ||
* | ||
* {{{ | ||
* scala> import cats.Id | ||
* scala> import cats.syntax.functor._ | ||
* | ||
* scala> ((1, 2): Id[(Int, Int)]).swapF == ((2, 1)) | ||
* res0: Boolean = true | ||
* }}} | ||
*/ | ||
def swapF(implicit F: Functor[F]): F[(B, A)] = F.map(fab)(_.swap) | ||
|
||
/** | ||
* Un-zips an `F[(A, B)]` consisting of element pairs or Tuple2 into two separate F's tupled. | ||
* | ||
* NOTE: Check for effect duplication, possibly memoize before | ||
* | ||
* {{{ | ||
* scala> import cats.Id | ||
* scala> import cats.syntax.functor._ | ||
* | ||
* scala> (5: Id[Int]).map(i => (i, i)).unzip == ((5, 5)) | ||
* res0: Boolean = true | ||
* }}} | ||
*/ | ||
def unzip(implicit F: Functor[F]): (F[A], F[B]) = F.unzip(fab) | ||
} |
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
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.
I think these docs and test would be nicer with a more interesting Functor than Id. Maybe Option?
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.
@johnynek the doc test for
unzip
was ported from the 2.11 branch so I decided to keep to the same type. TriedOption
but it failed for 2.13 becauseOption#unzip
is already defined in 2.13. Switched toChain
as it is Cats specific.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.
@johnynek is
Chain
fine or should replace it with something else?