Skip to content

Instantly share code, notes, and snippets.

View devlaam's full-sized avatar

Ruud Vlaming devlaam

  • Beta Research BV
  • Vienna, Austria
View GitHub Profile
@devlaam
devlaam / maybe.scala
Last active July 4, 2018 20:09
Handling nested contexts in Scala, a monad transformer done by hand.
/**
* 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 }