Skip to content

anonymous /gist:7897557
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Attempt for DSL in Scala on event that happened in Brno on 12/10/2013.
object define {
def alert(alertBuilder: AlertBuilder): Alert = {
alertBuilder.finish.getOrElse(
throw new IllegalStateException("can't build incomplete Alert")
)
}
}
abstract class AlertBuilder {
implicit def stringToAlertBuilder(string: String) = name
val props = scala.collection.mutable.Map.empty[String, Any]
def finish: Option[Alert] = {
Some(new Alert)
}
}
object having extends AlertBuilder {
def apply(alertBuilder: AlertBuilder): AlertBuilder = this
}
object name extends AlertBuilder {
def apply(alertBuilder: AlertBuilder): AlertBuilder = alertBuilder
def apply(string: String) = {
props += ("name" -> string)
this
}
}
object conditions extends AlertBuilder {
def apply(conditions: LogicOperation): AlertBuilder = {
props += ("conditions" -> conditions)
this
}
def any(list: List[Boolean]) = this
}
abstract class LogicOperation {
var conditions: List[Boolean] = _
def evaluate = conditions.reduceLeft(combine)
def combine(leftOp: Boolean, rightOp: Boolean): Boolean
def apply(conditions: List[Boolean]) = {
this.conditions = conditions
this
}
}
object any extends LogicOperation {
override def combine(l: Boolean, r: Boolean) = l || r
}
object all extends LogicOperation {
override def combine(l: Boolean, r: Boolean) = l && r
}
class Alert {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.