这是我之前的question:
的后续内容假设我有一些函数返回scalaz.Validaton
:
type Status[A] = ValidationNel[String, A]
val isPositive: Int => Status[Int] =
x => if (x > 0) x.success else s"$x not positive".failureNel
val isNegative: Int => Status[Int] =
x => if (x < 0) x.success else s"$x not negative".failureNel
我可以写一个新函数makeX
case class X(x1: Int, // should be positive
x2: Int, // should be positive
x3: Int) // should be negative
val makeX: (Int, Int, Int) => Status[X] = (x1, x2, x3) =>
(isPositive(x1) |@| isPositive(x2) |@| isNegative(x3)) (X.apply _)
我的问题是:如何以无点样式编写makeX
答案 0 :(得分:1)
这是一种让它无表情的时髦方式:
val makeX: (Int, Int, Int) => Status[X] = isPositive(_) |@| isPositive(_) |@| isNegative(_) apply X