The simple way of using FuncBindParam is:
"first_name" -> { (ns: NodeSeq) => SHtml.text(...) }
That will only generate the text if the tag first_name appears.
-Ross
On Mar 10, 2010, at 10:22 AM, Stuart Roebuck wrote:
> Okay, so I now understand what is happening a little better.
>
> When I saw a construct like:
>
> bind("example",xhtml,
> "first_name" -> SHtml.text(user.first_name, user.first_name(_)),
> "last_name" -> SHtml.text(user.last_name, user.last_name(_))
>
> it reminded me of a match with cases and my assumption was that each
> match would only be called if and when the match was found. In reality
> what appears to happen is that the item on the right hand side of the
> "->" is usually evaluated and then placed into a Map with the String
> like "first_name" being the key.
>
> So, if every binding is used in every case there is no big issue here,
> but if you have bindings that aren't all used they will none-the-less
> be evaluated every time you try to bind.
>
> Also every time the bind function is called a new Map appears to be
> generated and indexed in memory which doesn't seem as efficient as it
> could be.
>
> I can't help but wonder whether this could be converted to a form of
> match which would then be built at compile time and re-used and would
> only evaluate those matches that matched.
>
> In the meantime I see that you can convert the code above to:
>
> bind("example",xhtml,
> FuncBindParam("first_name", () => SHtml.text(user.first_name,
> user.first_name(_)),
> FuncBindParam("last_name", () => SHtml.text(user.last_name,
> user.last_name(_))
>
> to get a form of lazy evaluation.
>
>
> On Mar 10, 11:01 am, Stuart Roebuck <[email protected]> wrote:
>> I've been trying to figure why some binding is giving me a stack
>> overflow and I've discovered that if you use the BindHelpers.bind
>> method with a set of function BindParams, all the functions are
>> evaluated regardless of whether a match is found.
>>
>> So, for example, if you bind to an empty NodeSeq and have a BindParam
>> which will never match like:
>> "you won't find me here" -> { print("Got here!");
>> NodeSeq.Empty }
>> …you find that the print statement is called.
>>
>> This really surprised me. Is this intentional behaviour as it seems
>> to be a potential source of significant redundant processing?
>>
>> Stuart.
>
> --
> 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.
>
--
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.