Skip to content

Instantly share code, notes, and snippets.

@okumin
Last active June 9, 2016 16:15
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 okumin/494e068631a7d6295dfc to your computer and use it in GitHub Desktop.
Save okumin/494e068631a7d6295dfc to your computer and use it in GitHub Desktop.
def findMofu(id: Int): Future[CacheError | IOError | NotFound, Mofu] = ???
def createMofu(mofu: Mofu): Future[CacheError | IOError | DuplicateError, Mofu] = ???

val result = findMofu(5).recoverWith {
  case NotFound =>
    createMofu(Mofu(5)).recoverWith {
      case DuplicateError => UnknownError
    }
}

// findMofu の None が recoverWith され、createMofu の DuplicateError が UnknowError に変換されてるので↓のようになると推論される。
assert(result.isInstanceOf[Future[CacheError | IOError | UnknownError, Mofu])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment