Skip to content

Instantly share code, notes, and snippets.

@markhibberd
Created September 24, 2014 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markhibberd/427419ad6d1f83aaf6bc to your computer and use it in GitHub Desktop.
Save markhibberd/427419ad6d1f83aaf6bc to your computer and use it in GitHub Desktop.
def findMapM[F[_]: Monad, A, B](l: List[A])(f: A => F[Option[B]]): F[Option[B]] = l match {
case x :: xs =>
f(x).flatMap({
case Some(b) =>
b.some.pure[F]
case None =>
findMapM(xs)(f)
})
case Nil =>
none.pure[F]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment