Skip to content

Commit

Permalink
Merge pull request #10 from evolution-gaming/futur_option_collect_fix
Browse files Browse the repository at this point in the history
fix collect and collectWith to be not dependent on original type
  • Loading branch information
t3hnar committed Jun 7, 2018
2 parents 1b98f99 + 3d66415 commit a63a0e9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/scala/com/evolutiongaming/util/FutureOption.scala
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ sealed trait FutureOption[+T] {
def ?>>[L](l: => L)(implicit ec: ExecutionContext): FutureEither[L, T] = toRight(l)


def collect[TT >: T](pf: PartialFunction[T, TT])(implicit ec: ExecutionContext): FutureOption[TT]
def collect[TT](pf: PartialFunction[T, TT])(implicit ec: ExecutionContext): FutureOption[TT]

def collectWith[TT >: T](pf: PartialFunction[T, FutureOption[TT]])
def collectWith[TT](pf: PartialFunction[T, FutureOption[TT]])
(implicit ec: ExecutionContext): FutureOption[TT] = {

flatMap { x => if (pf isDefinedAt x) pf(x) else FutureOption.empty }
Expand Down Expand Up @@ -206,7 +206,7 @@ object FutureOption {
FutureEither(self map { _.toLeft(r) })
}

def collect[TT >: T](pf: PartialFunction[T, TT])(implicit ec: ExecutionContext): FutureOption[TT] = {
def collect[TT](pf: PartialFunction[T, TT])(implicit ec: ExecutionContext): FutureOption[TT] = {
HasFuture(self map { _ collect pf })
}

Expand All @@ -222,7 +222,7 @@ object FutureOption {
HasFuture(future recoverWith { case x if pf isDefinedAt x => pf(x).future })
}

override def toString = self.value match {
override def toString: String = self.value match {
case Some(Success(value)) => s"FutureOption($value)"
case Some(Failure(value)) => s"FutureOption($value)"
case None => "FutureOption(<not completed>)"
Expand Down Expand Up @@ -287,7 +287,7 @@ object FutureOption {
FutureEither(self.toLeft(r))
}

def collect[TT >: T](pf: PartialFunction[T, TT])(implicit ec: ExecutionContext): FutureOption[TT] = {
def collect[TT](pf: PartialFunction[T, TT])(implicit ec: ExecutionContext): FutureOption[TT] = {
HasOption(self collect pf)
}

Expand Down

0 comments on commit a63a0e9

Please sign in to comment.