- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Opinions on 3 state validation
Tue, 2012-02-21, 01:14
I have an implementation of formlets for reactive-web that I've been working on lately. I'm wondering as follows: Most implementations of validation that I've seen, whether Scalaz's, Websharper's, or Lift's Box, either hold a value or an error, not both. To me however it seems that a common scenario is a warning: There's an error message that has to be displayed, perhaps the user has to go through an extra confirmation step to proceed, but you don't actually want to prevent the user from proceeding if he knows what he's doing, so it definitely holds a value too. It seems like I need my own sealed trait with three case classes. Any thoughts?
Tue, 2012-02-21, 04:41
#2
Re: Opinions on 3 state validation
I use an (Option[Success], Option[Exception]) in cases like that. (Or List[Exception] if I want to accumulate them.) If you enrich a fold method onto Option (which I do anyway), and use match liberally, building custom classes doesn't really make things much easier. (So far, not enough easier that I want to build the custom set of classes.)
--Rex
On Mon, Feb 20, 2012 at 7:14 PM, Naftoli Gugenheim <naftoligug@gmail.com> wrote:
--Rex
On Mon, Feb 20, 2012 at 7:14 PM, Naftoli Gugenheim <naftoligug@gmail.com> wrote:
I have an implementation of formlets for reactive-web that I've been working on lately. I'm wondering as follows: Most implementations of validation that I've seen, whether Scalaz's, Websharper's, or Lift's Box, either hold a value or an error, not both. To me however it seems that a common scenario is a warning: There's an error message that has to be displayed, perhaps the user has to go through an extra confirmation step to proceed, but you don't actually want to prevent the user from proceeding if he knows what he's doing, so it definitely holds a value too. It seems like I need my own sealed trait with three case classes. Any thoughts?
Tue, 2012-02-21, 09:21
#3
Re: Opinions on 3 state validation
The purpose of the applicative functor for Validation is to allow computation to continue after failure. That is, the very existence of Validation is for the purpose tipi describe. Note that there is no possible corresponding monad for this (though there is one that fails and stops computing).
I have code, slides, examples and all that if you're interested enough.
On Feb 21, 2012 10:14 AM, "Naftoli Gugenheim" <naftoligug@gmail.com> wrote:I have an implementation of formlets for reactive-web that I've been working on lately. I'm wondering as follows: Most implementations of validation that I've seen, whether Scalaz's, Websharper's, or Lift's Box, either hold a value or an error, not both. To me however it seems that a common scenario is a warning: There's an error message that has to be displayed, perhaps the user has to go through an extra confirmation step to proceed, but you don't actually want to prevent the user from proceeding if he knows what he's doing, so it definitely holds a value too. It seems like I need my own sealed trait with three case classes. Any thoughts?
Much like a compiler will allow one to see more than one error
message per compilation attempt, I've got a Recorder class
that collects information, warnings and errors as well as
results. Additionally, one can specify how many errors can
occur prior to punting. If one or more errors occur, then there
are no results; but results will be returned regardless of how
much information and/or warnings are added to the Recorder.
If your application allows for more than one error to
be detected and possibly addressed by the user at a time,
you might consider a similar approach.
Richard
On 02/20/2012 04:14 PM, Naftoli Gugenheim wrote:
> I have an implementation of formlets for reactive-web that I've been
> working on lately. I'm wondering as follows: Most implementations of
> validation that I've seen, whether Scalaz's, Websharper's, or Lift's
> Box, either hold a value or an error, not both. To me however it seems
> that a common scenario is a warning: There's an error message that has
> to be displayed, perhaps the user has to go through an extra
> confirmation step to proceed, but you don't actually want to prevent the
> user from proceeding if he knows what he's doing, so it definitely holds
> a value too. It seems like I need my own sealed trait with three case
> classes. Any thoughts?
>