In Lift, for comprehensions are a nice way to do validation on user input. I find this optional function useful to validate optional input. Inspired by a message by Ross Mellgren on the lift user group.
An alternative would be
So what is going on:
- We check that the "required" parameter is present.
- We check that it's an integer.
- We check if the "optional" parameter is an integer.
If it's not present we return Full(Empty), if it's not an integer we return the Failure directly. If it's an integer we return a Full(Full(optional)).
And the type of the output is: Box[(Int, Box[Int])]
If there is a better way? Please leave a comment.