Lzy eval of certain Box arguments
http://groups.google.com/group/liftweb/browse_thread/thread/d01dd019a4bb0679
I usually use the ?~ method of the Box class in this manner:
myBox ?~ ("param %s is missing".format(param)). flatMap( ..... )
I use this a lot because it's an easy and concise way to add
meaningful error messages. But this means that String.format is being
evaluated every time, and in most cases this will not be necessary.
Wouldn't it be better is we would call the msg parameter in ?~ by
name?
So instead of
def ?~(msg: String): Failure = Failure(msg, Empty, Empty)
use this
def ?~(msg: => String): Failure = Failure(msg, Empty, Empty)
I'm not sure if there's a performance penalty in using named
parameters but the Loggable trait uses this for the same reason so I
immagine it's ignorable.
I usually use the ?~ method of the Box class in this manner:
myBox ?~ ("param %s is missing".format(param)). flatMap( ..... )
I use this a lot because it's an easy and concise way to add
meaningful error messages. But this means that String.format is being
evaluated every time, and in most cases this will not be necessary.
Wouldn't it be better is we would call the msg parameter in ?~ by
name?
So instead of
def ?~(msg: String): Failure = Failure(msg, Empty, Empty)
use this
def ?~(msg: => String): Failure = Failure(msg, Empty, Empty)
I'm not sure if there's a performance penalty in using named
parameters but the Loggable trait uses this for the same reason so I
immagine it's ignorable.
Leave a comment
(In revision:b4c0809958426494dd02a52d0cc31f2f955e970c) Addresses #1198. Made certain Box methods call-by-name
Branch: dpp_issue_1198
Branch: dpp_issue_1198
(In revision:a20bb12a157b6326ac420e0d30ce5588300e410b) Merge pull request #1228 from lift/dpp_issue_1198
Addresses #1198. Made certain Box methods call-by-name
Branch: master
Addresses #1198. Made certain Box methods call-by-name
Branch: master