假设我有几个案例类和函数来测试它们:
case class PersonName(...)
case class Address(...)
case class Phone(...)
def testPersonName(pn: PersonName): Either[String, PersonName] = ...
def testAddress(a: Address): Either[String, Address] = ...
def testPhone(p: Phone): Either[String, Phone] = ...
现在我定义了一个新的案例类Person
和一个测试函数,它很快就失败了。
case class Person(name: PersonName, address: Address, phone: Phone)
def testPerson(person: Person): Either[String, Person] = for {
pn <- testPersonName(person.name).right
a <- testAddress(person.address).right
p <- testPhone(person.phone).right
} yield person;
现在我想要函数testPerson
来累积错误,而不仅仅是快速失败。
我想testPerson
始终执行所有这些test*
功能并返回Either[List[String], Person]
。我怎样才能做到这一点 ?