Created
February 21, 2018 10:05
-
-
Save crakjie/0b843c2cecfd97c410b249493e5b73f2 to your computer and use it in GitHub Desktop.
optimistique sequance that prefer good result to bad ones
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def keepRight[F[_], G[_, _], B, C](l: F[G[B, C]])( | |
implicit //proofs | |
G: Bifoldable[G], | |
Me: scalaz.MonadError[G[B, ?], B], | |
F: MonadPlus[F], | |
Mobf: Monoid[F[B]], // proof we had a zero | |
Moc: Monoid[F[C]], // proof we had a zero | |
Mob: Monoid[B], // proof we can fold | |
eqB: scalaz.Equal[F[B]], | |
eqC: scalaz.Equal[F[C]], | |
f: Foldable[F] | |
): G[B, F[C]] = { | |
val (lefts, rights) = l.separate | |
if (Mobf.isMZero(lefts) && Moc.isMZero(rights)) | |
Me.pure(Moc.zero) | |
else if (Moc.isMZero(rights)) { | |
Me.raiseError(lefts.fold) | |
} else { | |
Me.pure(rights) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment