Skip to content
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

Merged
merged 3 commits into from
Oct 24, 2016
Merged

Conversation

zainab-ali
Copy link
Contributor

No description provided.

@codecov-io
Copy link

codecov-io commented Sep 24, 2016

Current coverage is 91.74% (diff: 100%)

Merging #1394 into master will increase coverage by 0.06%

@@             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          

Powered by Codecov. Last update b8603ec...af2c3b7

* res1: Option[List[Int]] = None
* }}}
*/
def sequenceM[G[_], A](fgfa: F[G[F[A]]])(implicit G: Applicative[G], F: FlatMap[F]): G[F[A]] =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sequenceA? since applicative

Copy link
Contributor

@kailuowang kailuowang Sep 30, 2016

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?

Copy link
Contributor Author

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

Copy link
Collaborator

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.

Copy link
Contributor

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.

@kailuowang
Copy link
Contributor

Thanks very much! @zainab-ali 👍 LGTM.

@travisbrown travisbrown mentioned this pull request Oct 18, 2016
13 tasks
@travisbrown
Copy link
Contributor

👍

@peterneyens
Copy link
Collaborator

I was not convinced about the name change at first, but after playing around with it I actually like the analogy between flatMap and flatTraverse :

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.

@kailuowang kailuowang merged commit ce0f24b into typelevel:master Oct 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants