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

traverse_ could be on UnorderedFoldable #2526

Open
johnynek opened this issue Sep 24, 2018 · 2 comments
Open

traverse_ could be on UnorderedFoldable #2526

johnynek opened this issue Sep 24, 2018 · 2 comments

Comments

@johnynek
Copy link
Contributor

Also, we should probably implement traverse_ in terms of foldMap not foldRight

def traverse_[A, B](fa: F[A])(fn: A => G[B])(implicit G: Applicative[G]): G[Unit] =
   foldMap(fn.andThen(_.unit))(Applicative.monoid[G, Unit])

foldRight is not the most efficient thing in the world since it leverages Eval (although, it may be that implementation is stack safe and the above is not.

@johnynek
Copy link
Contributor Author

Well, I guess it would have to take a CommutativeApplicative so maybe it is not the same function on UnorderedFoldable.

@LukaJCB
Copy link
Member

LukaJCB commented Sep 24, 2018

Yeah, I think you're right in that regard, probably should also think about how #2516 plays into this.

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

No branches or pull requests

2 participants