Skip to content

Commit

Permalink
PromiseEither projects should be filterable like scala's Either proje…
Browse files Browse the repository at this point in the history
…ction types
  • Loading branch information
softprops committed Jan 28, 2013
1 parent c40c8ca commit 42c5210
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core/src/main/scala/projections.scala
Expand Up @@ -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)
Expand All @@ -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]]) =
Expand Down

0 comments on commit 42c5210

Please sign in to comment.