如果我有一个 Matcher[A] 如何创建一个 Matcher[Iterable[A]] 只有当 Iterable 的每个元素都满足原始 Matcher 时才满足。
class ExampleSpec extends Specification {
def allSatisfy[A](m: => Matcher[A]): Matcher[Iterable[A]] = error("TODO")
def notAllSatisfy[A](m: => Matcher[A]): Matcher[Iterable[A]] = allSatisfy(m).not
"allSatisfy" should {
"Pass if all elements satisfy the expectation" in {
List(1, 2, 3, 4) must allSatisfy(beLessThan(5))
}
"Fail if any elements do not satisfy the expectation" in {
List(1, 2, 3, 5) must notAllSatisfy(beLessThan(5))
}
}
}