argonaut
argonaut copied to clipboard
Accumulate errors a la Validation
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?
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
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.
the CPSed reader sounds interesting, do you know where i could find a description of this technique?
@ritschwumm Not sure of any good references beside some code -https://github.com/pcapriotti/optparse-applicative/blob/master/Options/Applicative/Types.hs#L189-201
This is a really nice feature that I miss a lot - any plans on incorporating this in argonaut-6.1?
@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.