argonaut icon indicating copy to clipboard operation
argonaut copied to clipboard

Accumulate errors a la Validation

Open LeifW opened this issue 10 years ago • 6 comments

If I have case class Person(name: String, age: Int), and then I run Parse.decode[Person]("{}"}), I want "missing fields: name, age", not just "missing field: name"

Like maybe a cursor variant that returns Validation not /, so one could write a Decode instance like ((c --\ "name").as[String] |@| (c --\ "age").as[Int])(Person), to get notified of both fields missing?

LeifW avatar May 20 '14 22:05 LeifW

Like maybe a variant that uses ^ on Validations rather than flatMap on /'s here- https://github.com/argonaut-io/argonaut/blob/master/src/main/scala/argonaut/ACursor.scala#L116

LeifW avatar May 20 '14 22:05 LeifW

We should be able to do this. It might take a fair bit to not break the current style, but I thing it is doable and worth it. There is a pattern by which you can build an applicative structure using a CPS'd reader that would give you the behavior even for current flatMap style.

Also now is probably a good time to do it. We will have to make a few incompatible changes for 6.1 as anyway.

markhibberd avatar May 20 '14 22:05 markhibberd

the CPSed reader sounds interesting, do you know where i could find a description of this technique?

ritschwumm avatar May 20 '14 22:05 ritschwumm

@ritschwumm Not sure of any good references beside some code -https://github.com/pcapriotti/optparse-applicative/blob/master/Options/Applicative/Types.hs#L189-201

markhibberd avatar May 20 '14 22:05 markhibberd

This is a really nice feature that I miss a lot - any plans on incorporating this in argonaut-6.1?

eirirlar avatar Oct 21 '15 20:10 eirirlar

@eirirlar Well if it were to make it into a release it would be 6.2, but since the core lib in that doesn't depend on Scalaz at the very least it wouldn't be Validation.

As far as doing this without that it's probably still possible.

seanparsons avatar Oct 22 '15 11:10 seanparsons