-
-
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
collect and mapMaybe for MonadFilter? #842
Comments
collect
and mapMaybe
for MonadFilter
?
@alexknvl thank you for the detailed suggestion. I agree that some things along these lines could be useful. Some half-baked thoughts that come to mind as I ponder this:
|
Indeed: def partialFoldMap[F[_], A, B](fa: F[A])(pf: PartialFunction[A, B])(implicit F: Foldable[F], B: Monoid): B =
F.foldLeft(fa, B.empty)((b, a) => B.combine(b, if (pf.isDefinedAt(a)) pf(a) else B.empty)) And then to do list.partialFoldMap { case Xor.Right(x) => List(x) } |
@alexknvl I like your |
@alexknvl I'm going to go ahead and close this out, because I think that it was resolved by #1225. Please feel free to reopen or open a separate issue if there is anything that wasn't resolved by that PR. |
Along the lines of:
I am not sure about the names (I took
collect
from the standard Scala collection library andmapMaybe
from Haskell's Data.Maybe).Some random thoughts:
filter
andmap
could be beneficial performance-wise (an implementation forList
could do both in a single fold).List[Xor[A, B]] => List[B]
(or some otherMonadFilter
instance, sinceList
already hascollect
):mapMaybe
might not seem much better than usingflatMap
withpure
andempty
.A => Option[B]
functions.The text was updated successfully, but these errors were encountered: