Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

In Nick Partridge's presentation on deriving scalaz, based on an older version of scalaz, he introduces validations using a 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 validation with the failure 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 scalaz 7 equivalent of this combinator?

like image 237
Joe Kearney Avatar asked Sep 26 '22 13:09

Joe Kearney


1 Answers

This is now 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 there's a better way to find out this kind of thing than checking out the last 6.0 tag of the source, searching, and then comparing signatures.

like image 130
Travis Brown Avatar answered Nov 12 '22 21:11

Travis Brown