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:

  1. We check that the "required" parameter is present.
  2. We check that it's an integer.
  3. 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.