2

I'm trying to use Scalaz (scala 2.10, version 7.1 of ScalaZ) for validations. I have a case class with 13 fields, so I end up with 13 validations. I'm using the combinator to combine all of the validations and build the class if all are successful. If there are just 12 combinators, everything is fine. When I add the 13th, I get a message saying that "value |@| is not a member of scalaz.syntax.ApplicativeBuilder".

To reproduce, I fired up the REPL and tried to combine 12 items:

scala> (1.some |@| 2.some |@| 3.some |@| 4.some |@| 5.some |@| 6.some |@| 7.some |@|
        8.some |@| 9.some |@| 10.some |@| 11.some |@| 12.some ) 
        {_ + _ + _ + _ + _ + _ + _ + _ + _ +_ +_ +_ }
res11: Option[Int] = Some(78)

works just fine. I then tried to combine 13 items:

scala> (1.some |@| 2.some |@| 3.some |@| 4.some |@| 5.some |@| 6.some |@| 7.some |@|
        8.some |@| 9.some |@| 10.some |@| 11.some |@| 12.some |@| 13.some) 
        {_ + _ + _ + _ + _ + _ + _ + _ + _ +_ +_ +_ + _}
<console>:14: error: value |@| is not a member of
scalaz.syntax.ApplicativeBuilder[Option,Int,Int]#ApplicativeBuilder3[Int]#
ApplicativeBuilder4[Int]#ApplicativeBuilder5[Int]#ApplicativeBuilder6[Int]#
ApplicativeBuilder7[Int]#ApplicativeBuilder8[Int]#ApplicativeBuilder9[Int]#
ApplicativeBuilder10[Int]#ApplicativeBuilder11[Int]#ApplicativeBuilder12[Int]
(1.some |@| 2.some |@| 3.some |@| 4.some |@| 5.some |@| 6.some |@| 7.some |@| 8.some |@| 9.some |@| 10.some |@| 11.some |@| 12.some |@| 13.some) {_ + _ + _ + _ + _ + _ + _ + _ + _ +_ +_ +_ + _}

Is there another way to combine all of the validations?

bruce szalwinski
  • 724
  • 1
  • 8
  • 27
  • Digging through [Scalaz source code](https://github.com/scalaz/scalaz/blob/series/7.2.x/core/src/main/scala/scalaz/syntax/ApplicativeBuilder.scala), I see that ApplicativeBuilder only goes 12 levels deep :(. – bruce szalwinski Aug 14 '14 at 03:53
  • 2
    See my answer [here](http://stackoverflow.com/a/16943233/334519). – Travis Brown Aug 14 '14 at 03:54

1 Answers1

4

For the sake of completeness: yes, there is a limit on the number of items you can apply the applicative builder syntax to, and yes, it's twelve. In general, though, you can rewrite the following:

(a |@| b |@| c)(Function.uncurried(foo))

As:

c <*> (b <*> a.map(foo))

This syntax will work for more than twelve elements. See my answer here for more detail.

Community
  • 1
  • 1
Travis Brown
  • 138,631
  • 12
  • 375
  • 680