diff options
author | vlad <vlad@driver.xyz> | 2017-07-14 10:38:59 -0700 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-07-14 10:38:59 -0700 |
commit | 8353cc012328744c7cdfe0436e23d5e565bea570 (patch) | |
tree | 9ece288a43f30c3bd50393dd28fe17bf54b5e717 /src/main/scala/xyz/driver/pdsuicommon/computation | |
parent | 93eb4829c0d11959709e18a7b489343550633e83 (diff) | |
download | rest-query-8353cc012328744c7cdfe0436e23d5e565bea570.tar.gz rest-query-8353cc012328744c7cdfe0436e23d5e565bea570.tar.bz2 rest-query-8353cc012328744c7cdfe0436e23d5e565bea570.zip |
Clean-up + New User constructor from Driver User
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/computation')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/computation/Computation.scala | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/computation/Computation.scala b/src/main/scala/xyz/driver/pdsuicommon/computation/Computation.scala index 159c144..af7d051 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/computation/Computation.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/computation/Computation.scala @@ -72,6 +72,17 @@ final case class Computation[+R, +T](future: Future[Either[R, T]]) { }) } + def mapAll[R2, T2](onLeft: R => Computation[R2, T2])(onRight: T => Computation[R2, T2])( + onFailure: () => Computation[R2, T2])(implicit ec: ExecutionContext): Computation[R2, T2] = { + + Computation(future.flatMap { success => + if (success.isRight) onRight(success.right.get).future + else onLeft(success.left.get).future + } recoverWith { + case _ => onFailure().future + }) + } + def andThen(f: T => Any)(implicit ec: ExecutionContext): Computation[R, T] = map { a => f(a) a @@ -98,7 +109,6 @@ final case class Computation[+R, +T](future: Future[Either[R, T]]) { case Left(x) => x case Right(x) => x } - } object Computation { |