Von*_*onC 19
您在MEAP(早期访问)一书中有很好的资料来源

来自Debasish Ghosh的 DSL(博客:"程序员的反刍 ")
像scalatest这样的测试框架是DSL的经典例子:
test("pop is invoked on an empty stack") {
val emptyStack = new Stack[String]
evaluating { emptyStack.pop() } should produce [NoSuchElementException]
emptyStack should be ('empty)
}
Run Code Online (Sandbox Code Playgroud)
还有许多其他基于DSL的框架:
def songCountByArtistId: Query[GroupWithMeasures[Long,Long]] =
from(artists, songs)((a,s) =>
where(a.id === s.artistId)
groupBy(a.id)
compute(count)
)
lift-json提供了一个生成JSON的DSL.例如以下DSL:
("person" ->
("name" -> "Joe") ~
("age" -> 35) ~
("spouse" ->
("person" ->
("name" -> "Marilyn") ~
("age" -> 33)
)
)
)
Run Code Online (Sandbox Code Playgroud)
创建以下JSON:
{
"person": {
"name": "Joe",
"age": 35,
"spouse": {
"person": {
"name": "Marilyn",
"age": 33
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4458 次 |
| 最近记录: |