On Thu, Mar 12, 2009 at 8:58 AM, mal3 <[email protected]> wrote:
>
> Why did Lift invent the Can (or Box) class, when there's an existing
> Scala Option class?
>
> This is another naive 2-year-old question to ask. But I'm very curious
> to find out.
Heh... discussing this issue set off the worst flame war this list has ever
seen... it's not a naive question.
I was using the for comprehension to unpack REST requests. I discovered
that it was not very useful to have a simple "None" as the thing that's
returned from the for comprehension in the event of a missing or malformed
parameter. I wanted to have something that behaved like None but also
carried with it some data about why it wasn't some.
After noodling a bit, I came up with Can (now Box) which can be Full or
Empty or Failure or FailureParam... this allows:
for {name <- S.param("name") ?~ "name missing"
password <- S.param("password") ?~ "password missing"
valid <- validate(name, password) ?~ "Invalid account" ~> 403
cmd <- S.param("command") ?~ "command missing"
result <- performCommand(cmd)} yield result
As you can see, there's a syntactically pleasing mechanism for returning the
error reason (and in the case of an invalid account, the error code). The
Either construct was not available in August 2007 when I wrote Can. And I
don't believe Either works correctly in a for comprehension.
Questions?
Thanks,
David
>
>
> Mal.
>
> >
>
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Lift" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en
-~----------~----~----~----~------~----~------~--~---