Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use cartesian product |@| with latest versions of Cats?

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

like image 225
Loic Avatar asked Jun 17 '16 08:06

Loic


1 Answers

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

like image 145
Loic Avatar answered Nov 24 '22 08:11

Loic