Skip to content
Browse files

PromiseEither projects should be filterable like scala's Either proje…

…ction types
  • Loading branch information...
1 parent c40c8ca commit 42c5210ebbd8fca0d5c86c2ea91d27b9643dccb5 @softprops softprops committed
Showing with 10 additions and 0 deletions.
  1. +10 −0 core/src/main/scala/projections.scala
View
10 core/src/main/scala/projections.scala
@@ -24,6 +24,11 @@ object PromiseEither {
def foreach[U](f: A => U) {
underlying.addListener { () => underlying().left.foreach(f) }
}
+ def filter[X](p: A => Boolean): Promise[Option[Either[A,X]]] =
+ new EitherDelegate(underlying) with Promise[Option[Either[A,X]]] {
+ def claim = underlying().left.filter(p)
+ def replay = self.replay.filter(p)
+ }
}
class RightProjection[+A,+B](underlying: Promise[Either[A,B]]) { self =>
private def replay = new RightProjection(underlying.replay)
@@ -41,6 +46,11 @@ object PromiseEither {
def foreach(f: B => Unit) {
underlying.addListener { () => underlying().right.foreach(f) }
}
+ def filter[X](p: B => Boolean): Promise[Option[Either[X,B]]] =
+ new EitherDelegate(underlying) with Promise[Option[Either[X,B]]] {
+ def claim = underlying().right.filter(p)
+ def replay = self.replay.filter(p)
+ }
def values[A1 >: A, C]
(implicit ev: RightProjection[A, B] <:<
RightProjection[A1, Iterable[C]]) =

0 comments on commit 42c5210

Please sign in to comment.
Something went wrong with that request. Please try again.