Created
February 16, 2010 20:41
-
-
Save nkallen/305900 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Query { def i: Int } | |
// A Query and a Query Decorator | |
case class SimpleQuery(val i: Int) extends Query | |
case class TimingOutQuery(timeout: Int)(query: Query) extends Query { def i = query.i } | |
// Factories | |
type QueryFactory = Int => Query | |
// A thing that needs to make Queries | |
class QueryEvaluator(Query: QueryFactory)(k: Int) { | |
def apply() = Query(1 + k).i | |
} | |
// A specific set of decorators: | |
val myQueryFactory = SimpleQuery andThen TimingOutQuery(1) // andThen StatsColletingQuery(...) | |
// Using it | |
val queryEvaluator = new QueryEvaluator(myQueryFactory)(1) | |
println(queryEvaluator()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment