pau*_*aul 0 scala scalaz scala-cats
我在DSL中使用monad和comprenhension工作.由于我的客户端不知道Scala我试图隐藏这么多语法.到目前为止我有这个DSL
(for {
* <- Given("A message", message(path = "esb", version = TWO))
* <- And("With version 2.0", *)
* <- And("I make esb return 300", *)
* <- When("I make a request", *)
* <- Then("The return code is 500", *)
} yield ()).foldMap(scenario)
Run Code Online (Sandbox Code Playgroud)
这比使它们实现scalaTest要好得多,但这仍然可以吓到它们.
有没有办法隐藏使用隐式u其他机制的for/yield而只是离开DSL?
问候.
它必须是monad吗?
这样的事情可能更容易使用:
case class Given(
what: String,
ands: Seq[String] = Nil,
when: Option[String] = None,
then: Option[String] = None
) {
def And(s: String) = copy(ands = ands :+ s)
def When(s: String) = copy(when = Some(s))
def Then(s: String) = copy(then = Some(s))
def Run(scenario: Scenario) = ???
}
Run Code Online (Sandbox Code Playgroud)
你可以写点东西
Given("foo") And "bar" And "bat" When "baz" Then "bam" Run scenario
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
54 次 |
| 最近记录: |