To avoid null checking. If there is no cookie, you will get Empty otherwise
Full(cookie). Moreover with for-comprehensions you don't need any checks at
all. If there is no cookie then the doSomethingWithValue won't be evaluated.

On Mon, Nov 16, 2009 at 12:34 PM, DMB <[email protected]> wrote:

>
> I guess that could work, but why go to such lengths where there are
> much more straightforward solutions available? What do for
> comprehensions buy you in this case? I mean, 99% of the time, when I
> want to check for a cookie, I don't need the cookie itself or any of
> its properties. I need its value, or null if there's no cookie. Why
> not do something a-la RoR:
>
> S.cookieValue("cookieName")
>
> or a-la ASP.NET:
>
> val c = S.cookie("cookieName")
> if(c != null) {
>   val v = c.value
> }
>
> Or, indeed, both?
>
> On Nov 16, 1:22 am, Sergey Andreev <[email protected]> wrote:
> > Hi,
> >
> > For-comprehensions could help you out:
> >
> > for{
> >   cookie <- S.findCookie(cookieName)
> >   value <- cookie} doSomethingWithValue
> >
> > Regards
> >
> > On Mon, Nov 16, 2009 at 12:07 PM, DMB <[email protected]> wrote:
> >
> > > When I call findCookie it returns a Box. Then, the value on the cookie
> > > itself is also a box. Hence a ruby one-liner turns into something
> > > like:
> >
> > > val cookie = S.findCookie(cookieName)
> > > if(cookie.isDefined) {
> > >     val cookieVal = cookie.open_!.value.openOr(null)
> > >     // Do something with the cookie value
> > > }
> >
> > > This is very ugly, so I'm guessing I'm doing something wrong, but try
> > > as I might, I could not find any examples that would look even vaguely
> > > "right" to me.
> >
> > > Why can't findCookie return a simple, unboxed HTTPCookie object or
> > > null if cookie is not found?
> > > Why does the value inside a cookie need to also be Box'ed?
> >
> > > For the sake of comparison, here's how you do the same thing in RoR:
> > > v = cookies["cookieName"]
> > > // Do something with the cookie
> >
> > > or ASP.NET:
> > > var c = Request.Cookies["CookieName"]
> > > if(c != null) {
> > >   var v = c.Value
> > >   // Do something with the cookie
> > > }
> >
> > > I fail to see why Lift should be more complicated.
> >
> > > This is with Lift 1.1 M7
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to