Created
August 4, 2020 15:26
-
-
Save djspiewak/1b92a6e338f4e1537692e748c54b9743 to your computer and use it in GitHub Desktop.
This file contains 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 ifElseM[F[_]: FlatMap, A](branches: (F[Boolean], F[A])*, els: F[A]): F[A] = { | |
def loop(branches: List[(F[Boolean], F[A])]): F[A] = | |
branches match { | |
case (cond, conseq) :: tail => | |
cond.flatMap(if (_) conseq else loop(tail)) | |
case Nil => | |
els | |
} | |
loop(branches.toList) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment