-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport unzip method in functor typeclass for scala_2.11 (#3234)
* backported unzip method in functor typeclass * fixed nonfunctioning doctest
- Loading branch information
1 parent
4a7be5d
commit 7890320
Showing
6 changed files
with
42 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,30 @@ | ||
package cats | ||
package syntax | ||
|
||
import scala.language.implicitConversions | ||
|
||
trait FunctorSyntax extends Functor.ToFunctorOps | ||
|
||
private[syntax] trait FunctorSyntaxBinCompat0 { | ||
implicit final def catsSyntaxUnzipFunctorOps[F[_], A, B](fa: F[(A, B)]): UnzipFunctorOps[F, A, B] = | ||
new UnzipFunctorOps[F, A, B](fa) | ||
} | ||
|
||
final class UnzipFunctorOps[F[_], A, B](private val fab: F[(A, B)]) extends AnyVal { | ||
|
||
/** | ||
* 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.map(fab)(_._1), F.map(fab)(_._2)) | ||
} |
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