Scalaz:如何将函数应用到 ValidationNel 的成功?
Scalaz: how to apply a function to the success of a ValidationNel?
这是我的代码 x :->GetUsersByPhone
其中 x: scalaz.ValidationNel[ValidationError, Seq[PhoneNumberWithIdentifier]]
.
GetusersByPhone
只是一个包裹 Seq[PhoneNumberWithIdentifier]
的案例 class
我的问题是我认为正确的 :->
运算符,但它引发了这个错误:
[error] /home/simone/radicalbit/mpay-user/play/src/main/scala/com/next/mpay/users/validators/users/GetUsersByPhoneValidation.scala:31: value :-> is not a member of scalaz.ValidationNel[com.next.mpay.users.validators.ValidationError,Seq[com.next.mpay.users.persistence.PhoneNumberWithIdentifier]]
[error] possible cause: maybe a semicolon is missing before `value :->'?
[error] .:->(GetUsersByPhone)
[error] ^
我该如何解决?除了 scalaz._
和 scalaz.Scalaz._
之外,我还需要导入其他东西吗?
简单的 map
应该可以工作,因为 Validation
是右偏的:
x.map(GetUsersByPhone)
方法 :->
来自 Bifunctor
个实例。
但是虽然ValidationNel[A, B]
只是Validation[NonEmptyList[A], B]
的一个类型别名,而且Validation
有一个Bifunctor
实例,编译器仍然找不到Bifunctor
ValidationNel
.
实例
强制 ValidationNel
到相应的 Validation
也可以:
(x: Validation[NonEmptyList[ValidationError], Seq[PhoneNumberWithIdentifier]])
.:->(GetUsersByPhone)
这是我的代码 x :->GetUsersByPhone
其中 x: scalaz.ValidationNel[ValidationError, Seq[PhoneNumberWithIdentifier]]
.
GetusersByPhone
只是一个包裹 Seq[PhoneNumberWithIdentifier]
我的问题是我认为正确的 :->
运算符,但它引发了这个错误:
[error] /home/simone/radicalbit/mpay-user/play/src/main/scala/com/next/mpay/users/validators/users/GetUsersByPhoneValidation.scala:31: value :-> is not a member of scalaz.ValidationNel[com.next.mpay.users.validators.ValidationError,Seq[com.next.mpay.users.persistence.PhoneNumberWithIdentifier]]
[error] possible cause: maybe a semicolon is missing before `value :->'?
[error] .:->(GetUsersByPhone)
[error] ^
我该如何解决?除了 scalaz._
和 scalaz.Scalaz._
之外,我还需要导入其他东西吗?
简单的 map
应该可以工作,因为 Validation
是右偏的:
x.map(GetUsersByPhone)
方法 :->
来自 Bifunctor
个实例。
但是虽然ValidationNel[A, B]
只是Validation[NonEmptyList[A], B]
的一个类型别名,而且Validation
有一个Bifunctor
实例,编译器仍然找不到Bifunctor
ValidationNel
.
强制 ValidationNel
到相应的 Validation
也可以:
(x: Validation[NonEmptyList[ValidationError], Seq[PhoneNumberWithIdentifier]])
.:->(GetUsersByPhone)