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

Add Traverse.traverseM #1020

Merged
merged 1 commit into from
May 8, 2016
Merged

Conversation

peterneyens
Copy link
Collaborator

I have added Traverse.traverseM and added some examples to the traverse syntax.

* A traverse followed by flattening the inner result.
*/
def traverseM[G[_], A, B](fa: F[A])(f: A => G[F[B]])(implicit G: Applicative[G], F: FlatMap[F]): G[F[B]] =
G.map(traverse(fa)(f))(F.flatten)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We got F (FlatMap[F]) as an Applicative[F], but we could also use the Traverse itself : G.map(traverse(fa)(f)(this))(F.flatten).

I am not sure if there is a reason to choose one over the other ?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the version that you currently have is probably better, because Applicative.traverse ends up delegating through to Traverse.traverse anyway.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be called traverseA ? Consistent with replicateA. I think the M suffix is usually used when it has a Monad constraint.

Copy link
Contributor

Choose a reason for hiding this comment

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

@adelbertc The Applicative[G] is required on traverse also. Here I think of the M as "monadic", referring to the FlatMap[F]. I guess we could call it traverseF instead, though that runs the risk of being confused with Functor.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was not really sure about the M. traverseA seems a bit strange because we need FlatMap. traverseF could also be confusing with the flatMapF and mapF on (some) monad transformers.

Maybe we can call it traverseFlatten ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I totally did not see the FlatMap requirement.. the size of my screen stopped right at Applicative so I assumed that was all there was. I am good with traverseM in that case

@ceedubs
Copy link
Contributor

ceedubs commented May 7, 2016

👍 thanks!

@adelbertc
Copy link
Contributor

👍

@adelbertc adelbertc merged commit 40a1211 into typelevel:master May 8, 2016
@peterneyens peterneyens deleted the add-traverseM branch June 7, 2016 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants