Please note that Box also supports ParamFailure, which carries an additional object beyond the failuremessage to provide more detail. We use this extensively to provide error messages for logs with additionaldata that can be used for populating the UI, for example, and it makes Box no longer be conceptuallythe same as an Either[String,T] with sugar.
The drawback of ParamFailure is that the param's type is not reflected in the Box's type signature, soyou're relying on unchecked information when you write your pattern matches.
In my experience, Box'sAPI is both less noisy and more pleasant to use, so the tradeoff is worth it for me.
On Friday, April 11, 2014 12:21:37 PM UTC-4, Erik Post wrote:Hi Don,For a quick overview, have a look at this: http://typelevel.org/blog/2014/02/21/error-handling.html.One thing to be aware of is that Lift's Box[T] is like Either[String, T]. For useful error reporting, you might want a more informative type than String. That's where types such as \/, Validation and Either come in; they don't fix the error type to string, but you can do stuff like this:sealed trait Errorcase class ItemNotFound(key: Int) extends Error
case class ItemAlreadyExists(key: Int) extends Errorcase object DatabaseFailure(...) extends Errordef find(key: Int): Validation[Error, Item] = { ...case ... => Success(Item(...))case ... => Failure(ItemNotFound(key))case _ => Failure(DatabaseFailure)}If you want to return multiple errors, you can Stick a NonEmptyList[Error] in there instead of Error. I'm not sure what Antonio 'hates' about this. It's pretty convenient. You can chain \/ 'vertically' inside a for-comprehension, just like Box, while Validation can be used to string validations together 'horizontally'. There are lots of tutorials available, or you might want to drop by the #scalaz irc channel on Freenode.Cheers,ErikOn Friday, April 11, 2014 5:30:18 PM UTC+2, Donald McLean wrote:DonaldI'm just curious to know what people think.So, would I use something that would be like the opposite of a box/option where you would have Success, or Failure(error), or just use an Option where None == success?One of the things in Lift that I really like is the "Box" concept (where no result is different from and error).So one of the things that I'm working on, I have a different sort of situation. I have an operation (such as a validation) and either it will succeed, or it will produce one or more errors.
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
---
You received this message because you are subscribed to a topic in the Google Groups "Lift" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/liftweb/Uj0ENMsMtz4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to liftweb+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
One thing is if you use box without empty and you pattern match, you get a warning that you forgot one case. And it's annoying to have dummy match.
So a suggestion is, could there be some sealed trait that only full and failure extending. A subclass of box. Then we could use that on place of box in these types of cases. Then the pattern matching warning would be wiser. And its still box, and interchangeable with plain box.
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.
Hi Antonio,
To unsubscribe from this group and all its topics, send an email to liftweb+unsubscribe@googlegroups.com.
--
--
Lift, the simply functional web framework: http://liftweb.net
Code: http://github.com/lift
Discussion: http://groups.google.com/group/liftweb
Stuck? Help us help you: https://www.assembla.com/wiki/show/liftweb/Posting_example_code
---
You received this message because you are subscribed to the Google Groups "Lift" group.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+unsubscribe@googlegroups.com.
I don't understand the bigger problem, can you explain it better
Also I am pretty sure the type inference will work. It can do some pretty hairy lubs.
To unsubscribe from this group and stop receiving emails from it, send an email to liftweb+u...@googlegroups.com.