Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to add an Optional component onto any strategy #198

Merged
merged 2 commits into from
Dec 16, 2013
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ trait QueryStrategy[-Q,-L,X] extends Serializable { self =>
/** Used in your summingbird job to flatmap your keys, increment all these X with the value */
def index(key: L): Set[X]

def withOptionalStrategy: QueryStrategy[Option[Q],L,Option[X]] = new AbstractQueryStrategy[Option[Q], L, Option[X]] {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename .withOption?

def query(q: Option[Q]) = q match {
case Some(innerQ) => self.query(innerQ).map(Some(_))
case None => Set(None)
}

def index(key: L) = self.index(key).map(Some(_)).toSet + None
}

/** Create new strategy on a this and a second query strategy */
def cross[Q2,L2,X2](qs2: QueryStrategy[Q2,L2,X2]): QueryStrategy[(Q,Q2),(L,L2),(X,X2)] =
new AbstractQueryStrategy[(Q,Q2),(L,L2),(X,X2)] {
Expand Down