Chobeat Chobeat - 1 year ago 157
Scala Question

Scalaz: how to apply a function to the success of a ValidationNel?

this is my code

x :->GetUsersByPhone
x: scalaz.ValidationNel[ValidationError, Seq[PhoneNumberWithIdentifier]]

is simply a case class that wraps the

My problem is with the
operator that I think is correct but it raises this error:

[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[,Seq[]]
[error] possible cause: maybe a semicolon is missing before `value :->'?
[error] .:->(GetUsersByPhone)
[error] ^

How can I fix that? Do I need to import something else besides

Answer Source

Simple map should work, because Validation is right-biased:

Method :-> comes from a Bifunctor instance.

But although ValidationNel[A, B] is just a type alias for Validation[NonEmptyList[A], B], and there is a Bifunctor instance for Validation, the compiler still can't find a Bifunctor instance for ValidationNel.

Coercing ValidationNel to the respective Validation would also work though:

(x: Validation[NonEmptyList[ValidationError], Seq[PhoneNumberWithIdentifier]])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download