From 94626edb5cb980ce28c9761eaa5d59833d1feebd Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Mon, 12 Nov 2018 17:39:58 +0000 Subject: [PATCH 01/13] Add syntax for Bitraverse to allow independent traversal of sides This adds syntax for: * traverse * sequence * leftTraverse * leftSequence I am open to having better names, but I think these would be useful to have in cats-core. --- .../main/scala/cats/syntax/bitraverse.scala | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index 35fe883313..500cf937d3 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -11,14 +11,38 @@ private[syntax] trait BitraverseSyntax1 { fgagb: F[G[A], G[B]] ): NestedBitraverseOps[F, G, A, B] = new NestedBitraverseOps[F, G, A, B](fgagb) + + implicit final def catsSyntaxLeftNestedBitraverse[F[_, _]: Bitraverse, G[_], A, B]( + fgab: F[G[A], B] + ): LeftNestedBitraverseOps[F, G, A, B] = + new LeftNestedBitraverseOps[F, G, A, B](fgab) + + implicit final def catsSyntaxRightnestedBitraverse[F[_, _]: Bitraverse, G[_], A, B]( + fagb: F[A, G[B]] + ): RightNestedBitraverseOps[F, G, A, B] = + new RightNestedBitraverseOps[F, G, A, B](fagb) } final class BitraverseOps[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { def bitraverse[G[_]: Applicative, C, D](f: A => G[C], g: B => G[D])(implicit F: Bitraverse[F]): G[F[C, D]] = F.bitraverse(fab)(f, g) + def traverse[G[_], C](f: B => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, C]] = + F.bitraverse(fab)(G.pure(_), f) + def leftTraverse[G[_], C](f: A => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[C, B]] = + F.bitraverse(fab)(f, G.pure(_)) } final class NestedBitraverseOps[F[_, _], G[_], A, B](val fgagb: F[G[A], G[B]]) extends AnyVal { def bisequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = F.bisequence(fgagb) } + +final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) extends AnyVal { + def leftSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = + F.bitraverse(fgab)(identity, G.pure(_)) +} + +final class RightNestedBitraverseOps[F[_, _], G[_], A, B](val fagb: F[A, G[B]]) extends AnyVal { + def sequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A,B]] = + F.bitraverse(fagb)(G.pure(_), identity) +} From 07f3276f842daca35278521f9ee1c5ac6c0f0103 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Mon, 12 Nov 2018 17:59:00 +0000 Subject: [PATCH 02/13] Add syntax tests and accept prePR's style change --- core/src/main/scala/cats/syntax/bitraverse.scala | 2 +- tests/src/test/scala/cats/tests/SyntaxSuite.scala | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index 500cf937d3..bd6e185d22 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -43,6 +43,6 @@ final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) e } final class RightNestedBitraverseOps[F[_, _], G[_], A, B](val fagb: F[A, G[B]]) extends AnyVal { - def sequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A,B]] = + def sequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = F.bitraverse(fagb)(G.pure(_), identity) } diff --git a/tests/src/test/scala/cats/tests/SyntaxSuite.scala b/tests/src/test/scala/cats/tests/SyntaxSuite.scala index 30f28a867e..57564b0d32 100644 --- a/tests/src/test/scala/cats/tests/SyntaxSuite.scala +++ b/tests/src/test/scala/cats/tests/SyntaxSuite.scala @@ -299,9 +299,17 @@ object SyntaxSuite extends AllSyntaxBinCompat with AllInstances with AllSyntax { val fab = mock[F[A, B]] val gfcd = fab.bitraverse(f, g) + val gfad = fab.traverse(g) + val gfcb = fab.leftTraverse(f) val fgagb = mock[F[G[A], G[B]]] val gfab = fgagb.bisequence + + val fgab = mock[F[G[A], B]] + val gfab = fgab.leftSequence + + val fagb = mock[F[A, G[B]]] + val gfab = fagb.sequence } def testAlternativeMonad[F[_]: Alternative: Monad, G[_]: Foldable, H[_, _]: Bifoldable, A, B]: Unit = { From fe293fb8b35c86ea91f8afc3ca1eff0b116928d1 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Mon, 12 Nov 2018 21:09:34 +0000 Subject: [PATCH 03/13] Fix repeated variables in SyntaxSuite --- tests/src/test/scala/cats/tests/SyntaxSuite.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/src/test/scala/cats/tests/SyntaxSuite.scala b/tests/src/test/scala/cats/tests/SyntaxSuite.scala index 57564b0d32..03e18422c5 100644 --- a/tests/src/test/scala/cats/tests/SyntaxSuite.scala +++ b/tests/src/test/scala/cats/tests/SyntaxSuite.scala @@ -306,10 +306,10 @@ object SyntaxSuite extends AllSyntaxBinCompat with AllInstances with AllSyntax { val gfab = fgagb.bisequence val fgab = mock[F[G[A], B]] - val gfab = fgab.leftSequence + val gfab2 = fgab.leftSequence val fagb = mock[F[A, G[B]]] - val gfab = fagb.sequence + val gfab3 = fagb.sequence } def testAlternativeMonad[F[_]: Alternative: Monad, G[_]: Foldable, H[_, _]: Bifoldable, A, B]: Unit = { From cf547957506613b3ad5fadc9589a51235147c194 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Mon, 12 Nov 2018 21:13:31 +0000 Subject: [PATCH 04/13] Rename bitraverse's traverse and sequence to rightTraverse and rightSequence --- core/src/main/scala/cats/syntax/bitraverse.scala | 4 ++-- tests/src/test/scala/cats/tests/SyntaxSuite.scala | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index bd6e185d22..5869bba873 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -26,7 +26,7 @@ private[syntax] trait BitraverseSyntax1 { final class BitraverseOps[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { def bitraverse[G[_]: Applicative, C, D](f: A => G[C], g: B => G[D])(implicit F: Bitraverse[F]): G[F[C, D]] = F.bitraverse(fab)(f, g) - def traverse[G[_], C](f: B => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, C]] = + def rightTraverse[G[_], C](f: B => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, C]] = F.bitraverse(fab)(G.pure(_), f) def leftTraverse[G[_], C](f: A => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[C, B]] = F.bitraverse(fab)(f, G.pure(_)) @@ -43,6 +43,6 @@ final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) e } final class RightNestedBitraverseOps[F[_, _], G[_], A, B](val fagb: F[A, G[B]]) extends AnyVal { - def sequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = + def rightSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = F.bitraverse(fagb)(G.pure(_), identity) } diff --git a/tests/src/test/scala/cats/tests/SyntaxSuite.scala b/tests/src/test/scala/cats/tests/SyntaxSuite.scala index 03e18422c5..d5b8e9d1b4 100644 --- a/tests/src/test/scala/cats/tests/SyntaxSuite.scala +++ b/tests/src/test/scala/cats/tests/SyntaxSuite.scala @@ -299,7 +299,7 @@ object SyntaxSuite extends AllSyntaxBinCompat with AllInstances with AllSyntax { val fab = mock[F[A, B]] val gfcd = fab.bitraverse(f, g) - val gfad = fab.traverse(g) + val gfad = fab.rightTraverse(g) val gfcb = fab.leftTraverse(f) val fgagb = mock[F[G[A], G[B]]] @@ -309,7 +309,7 @@ object SyntaxSuite extends AllSyntaxBinCompat with AllInstances with AllSyntax { val gfab2 = fgab.leftSequence val fagb = mock[F[A, G[B]]] - val gfab3 = fagb.sequence + val gfab3 = fagb.rightSequence } def testAlternativeMonad[F[_]: Alternative: Monad, G[_]: Foldable, H[_, _]: Bifoldable, A, B]: Unit = { From 15f6f9ce598fe96657e8b2204636999b58765485 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Tue, 13 Nov 2018 13:59:30 +0000 Subject: [PATCH 05/13] Attempt to make new Bitraverse syntax binary compatible --- .../main/scala/cats/syntax/bitraverse.scala | 26 ++++++++++++------- core/src/main/scala/cats/syntax/package.scala | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index 5869bba873..00cac874bb 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -11,32 +11,40 @@ private[syntax] trait BitraverseSyntax1 { fgagb: F[G[A], G[B]] ): NestedBitraverseOps[F, G, A, B] = new NestedBitraverseOps[F, G, A, B](fgagb) +} + +final class BitraverseOps[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { + def bitraverse[G[_]: Applicative, C, D](f: A => G[C], g: B => G[D])(implicit F: Bitraverse[F]): G[F[C, D]] = + F.bitraverse(fab)(f, g) +} + +final class NestedBitraverseOps[F[_, _], G[_], A, B](val fgagb: F[G[A], G[B]]) extends AnyVal { + def bisequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = + F.bisequence(fgagb) +} +trait BitraverseSyntaxBinCompat0 { + implicit final def catsSyntaxBitraverseBinCompat0[F[_, _]: Bitraverse, A, B]( + fab: F[A, B] + ): BitraverseOpsBinCompat0[F, A, B] = + new BitraverseOpsBinCompat0[F, A, B](fab) implicit final def catsSyntaxLeftNestedBitraverse[F[_, _]: Bitraverse, G[_], A, B]( fgab: F[G[A], B] ): LeftNestedBitraverseOps[F, G, A, B] = new LeftNestedBitraverseOps[F, G, A, B](fgab) - implicit final def catsSyntaxRightnestedBitraverse[F[_, _]: Bitraverse, G[_], A, B]( fagb: F[A, G[B]] ): RightNestedBitraverseOps[F, G, A, B] = new RightNestedBitraverseOps[F, G, A, B](fagb) } -final class BitraverseOps[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { - def bitraverse[G[_]: Applicative, C, D](f: A => G[C], g: B => G[D])(implicit F: Bitraverse[F]): G[F[C, D]] = - F.bitraverse(fab)(f, g) +final class BitraverseOpsBinCompat0[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { def rightTraverse[G[_], C](f: B => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, C]] = F.bitraverse(fab)(G.pure(_), f) def leftTraverse[G[_], C](f: A => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[C, B]] = F.bitraverse(fab)(f, G.pure(_)) } -final class NestedBitraverseOps[F[_, _], G[_], A, B](val fgagb: F[G[A], G[B]]) extends AnyVal { - def bisequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = - F.bisequence(fgagb) -} - final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) extends AnyVal { def leftSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = F.bitraverse(fgab)(identity, G.pure(_)) diff --git a/core/src/main/scala/cats/syntax/package.scala b/core/src/main/scala/cats/syntax/package.scala index b00ab4373e..520eed4ccf 100644 --- a/core/src/main/scala/cats/syntax/package.scala +++ b/core/src/main/scala/cats/syntax/package.scala @@ -11,7 +11,7 @@ package object syntax { object bifunctor extends BifunctorSyntax object bifoldable extends BifoldableSyntax object binested extends BinestedSyntax - object bitraverse extends BitraverseSyntax + object bitraverse extends BitraverseSyntax with BitraverseSyntaxBinCompat0 @deprecated("use cats.syntax.semigroupal instead", "1.0.0-RC1") object cartesian extends SemigroupalSyntax object choice extends ChoiceSyntax From 8e1332c1ddef3d8a3aaf56ae6147b5966d4ba82b Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Tue, 13 Nov 2018 15:05:18 +0000 Subject: [PATCH 06/13] Add a new syntax bincompat to let me add new Bitraverse syntax to syntax.all --- core/src/main/scala/cats/syntax/all.scala | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/src/main/scala/cats/syntax/all.scala b/core/src/main/scala/cats/syntax/all.scala index 4dadad5a53..c4361c11cf 100644 --- a/core/src/main/scala/cats/syntax/all.scala +++ b/core/src/main/scala/cats/syntax/all.scala @@ -7,6 +7,7 @@ abstract class AllSyntaxBinCompat with AllSyntaxBinCompat1 with AllSyntaxBinCompat2 with AllSyntaxBinCompat3 + with AllSyntaxBinCompat4 trait AllSyntax extends AlternativeSyntax @@ -77,3 +78,5 @@ trait AllSyntaxBinCompat2 with ValidatedSyntaxBincompat0 trait AllSyntaxBinCompat3 extends UnorderedFoldableSyntax + +trait AllSyntaxBinCompat4 extends BitraverseSyntaxBinCompat0 \ No newline at end of file From a3414c8a3f7bccddfad294746c0b40a75f69738c Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Tue, 13 Nov 2018 15:31:48 +0000 Subject: [PATCH 07/13] Move Bitraverse new syntax into AllSyntaxBinCompat3 --- core/src/main/scala/cats/syntax/all.scala | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/core/src/main/scala/cats/syntax/all.scala b/core/src/main/scala/cats/syntax/all.scala index c4361c11cf..d86728b513 100644 --- a/core/src/main/scala/cats/syntax/all.scala +++ b/core/src/main/scala/cats/syntax/all.scala @@ -7,7 +7,6 @@ abstract class AllSyntaxBinCompat with AllSyntaxBinCompat1 with AllSyntaxBinCompat2 with AllSyntaxBinCompat3 - with AllSyntaxBinCompat4 trait AllSyntax extends AlternativeSyntax @@ -77,6 +76,4 @@ trait AllSyntaxBinCompat2 with ListSyntaxBinCompat0 with ValidatedSyntaxBincompat0 -trait AllSyntaxBinCompat3 extends UnorderedFoldableSyntax - -trait AllSyntaxBinCompat4 extends BitraverseSyntaxBinCompat0 \ No newline at end of file +trait AllSyntaxBinCompat3 extends UnorderedFoldableSyntax with BitraverseSyntaxBinCompat0 From ad87d8e53ea3a5a4342111e82dd65baa381aac66 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Mon, 3 Dec 2018 15:50:54 +0000 Subject: [PATCH 08/13] Drop rightTraverse and rightSequence from this PR --- core/src/main/scala/cats/syntax/bitraverse.scala | 11 ----------- tests/src/test/scala/cats/tests/SyntaxSuite.scala | 4 ---- 2 files changed, 15 deletions(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index 8933f88e2f..d42bafc365 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -32,15 +32,9 @@ trait BitraverseSyntaxBinCompat0 { fgab: F[G[A], B] ): LeftNestedBitraverseOps[F, G, A, B] = new LeftNestedBitraverseOps[F, G, A, B](fgab) - implicit final def catsSyntaxRightnestedBitraverse[F[_, _]: Bitraverse, G[_], A, B]( - fagb: F[A, G[B]] - ): RightNestedBitraverseOps[F, G, A, B] = - new RightNestedBitraverseOps[F, G, A, B](fagb) } final class BitraverseOpsBinCompat0[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { - def rightTraverse[G[_], C](f: B => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, C]] = - F.bitraverse(fab)(G.pure(_), f) def leftTraverse[G[_], C](f: A => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[C, B]] = F.bitraverse(fab)(f, G.pure(_)) } @@ -49,8 +43,3 @@ final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) e def leftSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = F.bitraverse(fgab)(identity, G.pure(_)) } - -final class RightNestedBitraverseOps[F[_, _], G[_], A, B](val fagb: F[A, G[B]]) extends AnyVal { - def rightSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = - F.bitraverse(fagb)(G.pure(_), identity) -} diff --git a/tests/src/test/scala/cats/tests/SyntaxSuite.scala b/tests/src/test/scala/cats/tests/SyntaxSuite.scala index d5b8e9d1b4..3b9d0ae31f 100644 --- a/tests/src/test/scala/cats/tests/SyntaxSuite.scala +++ b/tests/src/test/scala/cats/tests/SyntaxSuite.scala @@ -299,7 +299,6 @@ object SyntaxSuite extends AllSyntaxBinCompat with AllInstances with AllSyntax { val fab = mock[F[A, B]] val gfcd = fab.bitraverse(f, g) - val gfad = fab.rightTraverse(g) val gfcb = fab.leftTraverse(f) val fgagb = mock[F[G[A], G[B]]] @@ -307,9 +306,6 @@ object SyntaxSuite extends AllSyntaxBinCompat with AllInstances with AllSyntax { val fgab = mock[F[G[A], B]] val gfab2 = fgab.leftSequence - - val fagb = mock[F[A, G[B]]] - val gfab3 = fagb.rightSequence } def testAlternativeMonad[F[_]: Alternative: Monad, G[_]: Foldable, H[_, _]: Bifoldable, A, B]: Unit = { From 558b3723f6f8e3d51d46d9d035874000aeb5d4e2 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Sat, 22 Dec 2018 17:55:33 +0000 Subject: [PATCH 09/13] scalafmt --- core/src/main/scala/cats/syntax/all.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/syntax/all.scala b/core/src/main/scala/cats/syntax/all.scala index 27428863a0..41a8575027 100644 --- a/core/src/main/scala/cats/syntax/all.scala +++ b/core/src/main/scala/cats/syntax/all.scala @@ -79,4 +79,7 @@ trait AllSyntaxBinCompat2 trait AllSyntaxBinCompat3 extends UnorderedFoldableSyntax with Function1Syntax -trait AllSyntaxBinCompat4 extends TraverseFilterSyntaxBinCompat0 with ParallelApplySyntax with BitraverseSyntaxBinCompat0 +trait AllSyntaxBinCompat4 + extends TraverseFilterSyntaxBinCompat0 + with ParallelApplySyntax + with BitraverseSyntaxBinCompat0 From 76d878727b8d3102c50f7accc7b88a07629da61c Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Thu, 10 Jan 2019 11:58:41 +0000 Subject: [PATCH 10/13] Add scaladoc on leftSequence/leftTraverse --- .../main/scala/cats/syntax/bitraverse.scala | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index d42bafc365..e3497b4afb 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -35,11 +35,47 @@ trait BitraverseSyntaxBinCompat0 { } final class BitraverseOpsBinCompat0[F[_, _], A, B](val fab: F[A, B]) extends AnyVal { + + /** + * Traverse over the left side of the structure. + * For the right side, use the standard `traverse` from [[cats.Traverse]]. + * + * Example: + * {{{ + * scala> import cats.implicits._ + * + * scala> val intAndString: (Int, String) = (7, "test") + * + * scala> intAndString.leftTraverse(i => Option(i).filter(_ > 5)) + * res1: Option[(Int, String)] = Some(7, "test") + * + * scala> intAndString.leftTraverse(i => Option(i).filter(_ < 5)) + * res2: Option[(Int, String)] = None + * }}} + */ def leftTraverse[G[_], C](f: A => G[C])(implicit F: Bitraverse[F], G: Applicative[G]): G[F[C, B]] = F.bitraverse(fab)(f, G.pure(_)) } final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) extends AnyVal { + + /** + * Sequence the left side of the structure. + * For the right side, use the standard `sequence` from [[cats.Traverse]]. + * + * Example: + * {{{ + * scala> import cats.implicits._ + * + * scala> val optionalErrorNone: Either[[Option[String], Int] = Either.right(123) + * scala> optionalErrorNone.leftSequence + * res1: Option[Either[String, Int]] = None + * + * scala> val optionalErrorSome: Either[[Option[String], Int] = Either.left(Some("something went wrong")) + * scala> optionalErrorSome.leftSequence + * res2: Option[Either[String, Int]] = Some(Left(something went wrong)) + * }}} + */ def leftSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = F.bitraverse(fgab)(identity, G.pure(_)) } From 14bbe6847696c3c20d0d549bfd030030ee565a44 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Thu, 10 Jan 2019 12:09:10 +0000 Subject: [PATCH 11/13] Fix doctests for leftTraverse/leftSequence --- core/src/main/scala/cats/syntax/bitraverse.scala | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index e3497b4afb..0f5676cf2d 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -47,7 +47,7 @@ final class BitraverseOpsBinCompat0[F[_, _], A, B](val fab: F[A, B]) extends Any * scala> val intAndString: (Int, String) = (7, "test") * * scala> intAndString.leftTraverse(i => Option(i).filter(_ > 5)) - * res1: Option[(Int, String)] = Some(7, "test") + * res1: Option[(Int, String)] = Some(7,test) * * scala> intAndString.leftTraverse(i => Option(i).filter(_ < 5)) * res2: Option[(Int, String)] = None @@ -67,13 +67,17 @@ final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) e * {{{ * scala> import cats.implicits._ * - * scala> val optionalErrorNone: Either[[Option[String], Int] = Either.right(123) - * scala> optionalErrorNone.leftSequence - * res1: Option[Either[String, Int]] = None + * scala> val optionalErrorRight: Either[Option[String], Int] = Either.right(123) + * scala> optionalErrorRight.leftSequence + * res1: Option[Either[String, Int]] = Some(Right(123)) * - * scala> val optionalErrorSome: Either[[Option[String], Int] = Either.left(Some("something went wrong")) - * scala> optionalErrorSome.leftSequence + * scala> val optionalErrorLeftSome: Either[Option[String], Int] = Either.left(Some("something went wrong")) + * scala> optionalErrorLeftSome.leftSequence * res2: Option[Either[String, Int]] = Some(Left(something went wrong)) + * + * scala> val optionalErrorLeftNone: Either[Option[String], Int] = Either.left(Some("something went wrong")) + * scala> optionalErrorLeftNone.sequence + * res3: Option[Either[String,Int]] = None * }}} */ def leftSequence(implicit F: Bitraverse[F], G: Applicative[G]): G[F[A, B]] = From 4b0551082fcfe28f6ac7719e2857e889bd5423b2 Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Thu, 10 Jan 2019 12:22:27 +0000 Subject: [PATCH 12/13] Fix doctests for leftTraverse/leftSequence again --- core/src/main/scala/cats/syntax/bitraverse.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index 0f5676cf2d..68a8fc7e90 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -76,7 +76,7 @@ final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) e * res2: Option[Either[String, Int]] = Some(Left(something went wrong)) * * scala> val optionalErrorLeftNone: Either[Option[String], Int] = Either.left(Some("something went wrong")) - * scala> optionalErrorLeftNone.sequence + * scala> optionalErrorLeftNone.leftSequence * res3: Option[Either[String,Int]] = None * }}} */ From 28f6c9a12e396227e10f800f1d003266b6eea79c Mon Sep 17 00:00:00 2001 From: Andi Miller Date: Thu, 10 Jan 2019 12:43:23 +0000 Subject: [PATCH 13/13] Fix doctests for leftTraverse/leftSequence yet again --- core/src/main/scala/cats/syntax/bitraverse.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/cats/syntax/bitraverse.scala b/core/src/main/scala/cats/syntax/bitraverse.scala index 68a8fc7e90..ff3ee775b5 100644 --- a/core/src/main/scala/cats/syntax/bitraverse.scala +++ b/core/src/main/scala/cats/syntax/bitraverse.scala @@ -47,7 +47,7 @@ final class BitraverseOpsBinCompat0[F[_, _], A, B](val fab: F[A, B]) extends Any * scala> val intAndString: (Int, String) = (7, "test") * * scala> intAndString.leftTraverse(i => Option(i).filter(_ > 5)) - * res1: Option[(Int, String)] = Some(7,test) + * res1: Option[(Int, String)] = Some((7,test)) * * scala> intAndString.leftTraverse(i => Option(i).filter(_ < 5)) * res2: Option[(Int, String)] = None @@ -75,7 +75,7 @@ final class LeftNestedBitraverseOps[F[_, _], G[_], A, B](val fgab: F[G[A], B]) e * scala> optionalErrorLeftSome.leftSequence * res2: Option[Either[String, Int]] = Some(Left(something went wrong)) * - * scala> val optionalErrorLeftNone: Either[Option[String], Int] = Either.left(Some("something went wrong")) + * scala> val optionalErrorLeftNone: Either[Option[String], Int] = Either.left(None) * scala> optionalErrorLeftNone.leftSequence * res3: Option[Either[String,Int]] = None * }}}