Scalaz 7 equivalent `<| * |> `from scalaz 6

In Nick Partridge's View of scalaz's derivation based on an old version of scalaz, he introduces checks using the function:

 def even(x: Int): Validation[NonEmptyList[String], Int] = if (x % 2 == 0) x.success else { s"not even: $x".wrapNel.failure } 

Then he combines this using

 even(1) <|*|> even(2) 

which applies the test and returns a confirmation with an error message. Using scalaz 7, I get

 scala> even(1) <|*|> even(2) <console>:18: error: value <|*|> is not a member of scalaz.Validation[scalaz.NonEmptyList[String],Int] even(1) <|*|> even(2) ^ 

What is the equivalent of this rangaral 7?

+5
source share
2 answers

Now this is called tuple , so you can write, for example:

 import scalaz._, Scalaz._ def even(x: Int): Validation[NonEmptyList[String], Int] = if (x % 2 == 0) x.success else s"not even: $x".failureNel val pair: ValidationNel[String, (Int, Int)] = even(1) tuple even(2) 

Unfortunately, I'm not sure that there is a better way to find out about this than to check the latest source tag 6.0, search, and then compare signatures.

+5
source

Do you want to use the operator |@| .

 scala> (even(1) |@| even(2) |@| even(3)) { (_,_,_) } <console> Failure(NonEmptyList(not even: 1, not even: 3)) scala> (even(2) |@| even(4) |@| even(6)) { (_,_,_) } <console> Success((2,4,6)) 

compare this with the tuple statement:

 scala> even(1) tuple even(2) tuple even(3) <console> Failure(NonEmptyList(not even: 1, not even: 3)) scala> even(2) tuple even(4) tuple even(6) <console> Success(((2,4),6)) 
-1
source

Source: https://habr.com/ru/post/1233183/


All Articles