Skip to content

Instantly share code, notes, and snippets.

@matthandlersux
Last active August 29, 2015 13:57
Show Gist options
  • Save matthandlersux/9403412 to your computer and use it in GitHub Desktop.
Save matthandlersux/9403412 to your computer and use it in GitHub Desktop.

Revisions

  1. matt handler revised this gist Mar 7, 2014. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -2,13 +2,13 @@ package util

    object FutureOption {
    implicit class WithFutureOption[A](self: Future[Option[A]]) {
    def flatMapOption[T](e: Exception)(f: A => Future[T]): Future[T] = {
    def flatMapOption[T](e: => Exception)(f: A => Future[T]): Future[T] = {
    self flatMap {
    _ map f getOrElse Future.failed(e)
    }
    }

    def mapOption[T](e: Exception)(f: A => T): Future[T] = {
    def mapOption[T](e: => Exception)(f: A => T): Future[T] = {
    self map {
    _ map f getOrElse (throw e)
    }
  2. matt handler revised this gist Mar 7, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    package util

    object FlatMapOption {
    object FutureOption {
    implicit class WithFutureOption[A](self: Future[Option[A]]) {
    def flatMapOption[T](e: Exception)(f: A => Future[T]): Future[T] = {
    self flatMap {
  3. matt handler created this gist Mar 7, 2014.
    17 changes: 17 additions & 0 deletions gistfile1.scala
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    package util

    object FlatMapOption {
    implicit class WithFutureOption[A](self: Future[Option[A]]) {
    def flatMapOption[T](e: Exception)(f: A => Future[T]): Future[T] = {
    self flatMap {
    _ map f getOrElse Future.failed(e)
    }
    }

    def mapOption[T](e: Exception)(f: A => T): Future[T] = {
    self map {
    _ map f getOrElse (throw e)
    }
    }
    }
    }