12

I've migrated some code using cats 0.2 to cats 0.6, and my code is not wroking anymore :

import cats.data.Validated
import cats.std.all._

val valid1: Validated[List[String], Int] = valid(1)
val valid2: Validated[List[String], Int] = valid(2)
(valid1 |@| valid2).map{_+_}

Compiler says :

Error:(48, 6) value |@| is not a member of 

cats.data.Validated[List[String],Int]
(valid1 |@| valid2).map{_+_}
    ^

I did not find anything in the documentation regarding this, should I had an import or declare an implicit or something?

I've managed to use product instead of |@| but it's not as convenient as it produces nested tuples. Let's say I have 4 validated to combine :

  (valid1 product valid2 product valid3 product valid4)
    .map{case (((v1, v2), v3), v4) => v1 + v2 + v3 + v4}

Thanks

Loic
  • 3,310
  • 4
  • 25
  • 43
  • 2
    You'll need to import the syntax for applicative builder. cats.syntax.all._ will do it, not sure of the specific import – melps Jun 17 '16 at 08:33
  • @meps thanks it works! – Loic Jun 17 '16 at 08:50
  • 3
    It is easier to use `import cats.implicits._` then you don't need to search for the correct `cats.std.x` or `cats.syntax.y` (the specific you needed here was `cats.syntax.cartesian._`). – Peter Neyens Jun 17 '16 at 09:52

1 Answers1

5

As @meps said in comments, missing import was cats.syntax.all._

Loic
  • 3,310
  • 4
  • 25
  • 43
  • 1
    `|@|` no longer exists. In case it helps anyone, `(ma |@| mb).map` is replaced by `(ma, mb).mapN`. – Lasf Jul 21 '20 at 04:19