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

ZIO.foreach and friends for a NonEmptyList #315

Open
hmemcpy opened this issue Mar 14, 2021 · 5 comments
Open

ZIO.foreach and friends for a NonEmptyList #315

hmemcpy opened this issue Mar 14, 2021 · 5 comments

Comments

@hmemcpy
Copy link

hmemcpy commented Mar 14, 2021

It would be great if this project could provide an extension for ZIO that added ZIO.foreach/collectAll etc for Cats NEL.

@neko-kai
Copy link
Member

It doesn't seem like it can be done because implicit class search only happens if the method with the same name does not exist on the class, even if the type of the argument doesn't match. Example: https://scastie.scala-lang.org/6Qdbo7PhQwKkA2oOo2VM3g

One weird thing that could enable this is providing implicit conversion NonEmptyList[A] => Iterable[A] since ZIO.foreach works with any iterable - but then you wouldn't get a Nel back as a result.

You could also just use cats' .traverse syntax...

@hmemcpy
Copy link
Author

hmemcpy commented Mar 15, 2021

Yeah, I thought about adding the implicit conversion to Iterable. I didn't realize the extension method trick wouldn't work... And we do use traverse for those places that expose NELs, but it would be nice having a consistency with ZIO. Anyway, thanks, I'll try seeing if adding a conversion will be enough!

@adamgfraser
Copy link
Contributor

Perhaps we could provide it under a different name? foreachNonEmptyList? I ran into this too.

@neko-kai
Copy link
Member

neko-kai commented Apr 2, 2021

If that would work for @hmemcpy too let's add a foreachNonEmptyList/foreachNel/etc extension method

@joroKr21
Copy link
Contributor

If you are using Cats / Cats Effect you can just do nel.traverse etc.

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

4 participants