-
-
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
Adding sequenceM method to Traverse #1394
Conversation
Current coverage is 91.74% (diff: 100%)@@ master #1394 diff @@
==========================================
Files 239 240 +1
Lines 3607 3609 +2
Methods 3544 3538 -6
Messages 0 0
Branches 62 70 +8
==========================================
+ Hits 3307 3311 +4
+ Misses 300 298 -2
Partials 0 0
|
* res1: Option[List[Int]] = None | ||
* }}} | ||
*/ | ||
def sequenceM[G[_], A](fgfa: F[G[F[A]]])(implicit G: Applicative[G], F: FlatMap[F]): G[F[A]] = |
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.
sequenceA? since applicative
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.
Well this one is corresponding traverseM
, maybe both should be renamed? (if we ended up doing that we need to add the "breaking change" label. ) Also, maybe implementing this with traverseM
would make the connection more obvious?
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.
What about flatTraverse
or flatSequence
, taking the convention from Scala's flatMap
? I realize that this isn't well established in other languages, but both traverseM
and sequenceM
aren't as self explanatory
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.
There was a similar conversation when I added traverseM
in #1020.
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.
Sorry for the delayed response. I like flatTraverse
and flatSequence
, they make sense to me.
Thanks very much! @zainab-ali 👍 LGTM. |
👍 |
I was not convinced about the name change at first, but after playing around with it I actually like the analogy between def smallerNaturals(i: Int): List[Int] =
List.range(1, Math.max(i, 1))
def smallerNaturalsOpt(i: Int): Option[List[Int]] =
if (i <= 1) None else Some(List.range(1, i))
List(2,3,4).flatMap(smallerNaturals)
// List[Int] = List(1, 1, 2, 1, 2, 3)
List(2,3,4).flatTraverse(smallerNaturalsOpt)
// Option[List[Int]] = Some(List(1, 1, 2, 1, 2, 3)) So 👍 , thanks @zainab-ali. |
No description provided.