Skip to content

Instantly share code, notes, and snippets.


Ruud Vlaming devlaam

  • Beta Research BV
  • Bergen, The Netherlands
View GitHub Profile
devlaam / maybe.scala
Last active Jul 4, 2018
Handling nested contexts in Scala, a monad transformer done by hand.
View maybe.scala
* Helper class to use future-options in for-comprehension-loops
* Use this class as a combined future/option so handling becomes more easy on these
* objects. Any empty options will short-circuit the future chain and any exceptions
* in a future will result in a future-none result.
* Available under MIT license.
case class Maybe[+A](val maybe: Future[Option[A]]) extends AnyVal
{ import scala.util.control.NonFatal
def value = maybe.recoverWith{ case NonFatal(_) => Maybe.never }
You can’t perform that action at this time.