Yes, this does help a bit.

I actually understand the Can (and Option) very well, and I think it's a 
great idea (though the added advantage of the Can doesn't seem to be 
heavily used yet).

The problem I was having was dealing with cans inside cans inside cans. 
But after reading everything everyone sent, I think I've got it now:

val p = 
S.request.flatMap(_.location).flatMap(_.createDefaultLink).map(_.text)

<a href={p.openOr("")}>This page</a>

Or this:

val p = for (req <- S.request;
              loc <- req.location;
              txt <- loc.createDefaultLink) yield txt

<a href={p.openOr("").toString}>This page</a>

Of course, now that I know, I'll just use S.uri.

Thanks again for all the help!

Chas.

David Pollak wrote:
> Charles,
> 
> A Can is a container... it can contain a thing or be empty.
> 
> You can transform the contents of a Can from one thing to another using 
> map().  map() on Can, Option, List is exactly the same as map() on Array 
> in Ruby:
> irb(main):004:0> [1,2,3].map{|v| v.to_s + " Cats"}
> => ["1 Cats", "2 Cats", "3 Cats"]
> 
> This is just like in Scala:
> scala> List(1,2,3).map(v => v.toString + " Cats")
> res0: List[java.lang.String] = List(1 Cats, 2 Cats, 3 Cats)
> 
> In Ruby, when you access the first element of an Array that has no 
> elements, you get 'nil' back.  In Scala, you get an exception.  This 
> allows you to tell the difference between [nil][0] and [][0] which are 
> the same in Ruby.
> 
> The most syntactically pleasing way of extracting things from List, Can, 
> Option in Scala is the "for" comprehension:
> 
> scala> for (a <- Some(3);
>      |        b <- Some(4)) yield a * b
> res1: Option[Int] = Some(12)
> 
> 
> Does that help?
> 
> Thanks,
> 
> David
> 
> 
> 
> Charles F. Munat wrote:
>> Thanks. I have read everything I could find on this but I think I'm just 
>> a bit dense about it. Probably, it's just unfamiliarity with the syntax 
>> of Scala as a whole and functional programming in general (or maybe I'm 
>> just stupid). Hopefully, at some point the light bulb will come on and 
>> this will seem easy. I'll read the blog post.
>>
>> Chas.
>>
>> David Pollak wrote:
>>   
>>> Please also see:
>>> http://blog.lostlake.org/index.php?/archives/50-The-Scala-Option-class-and-how-lift-uses-it.html
>>>
>>> Can[T] is just like Option[T]
>>>
>>> Marius wrote:
>>>     
>>>> to get stuff out of a can you can do:
>>>>
>>>> 1. Pattern matching
>>>>
>>>> having c a Can[String]
>>>>
>>>> c match {
>>>>   case Full(value) => //do something with the value
>>>>   case _ =>
>>>> }
>>>>
>>>> 2. call open_!(if you're sure your can is not empty) or openOr
>>>>
>>>> Br's,
>>>> Marius
>>>>
>>>> On Oct 15, 3:22 am, "Charles F. Munat" <[EMAIL PROTECTED]> wrote:
>>>>   
>>>>       
>>>>> I must be very dense, but these cans are kicking my butt (kicking my
>>>>> can?). No matter what I do, I seem to end up with everything back in the
>>>>> can! I just... want... to get... the goodies... OUT!
>>>>>
>>>>> An example:
>>>>>
>>>>> How do I extract the URI of the current page from S.request?
>>>>>
>>>>> I am currently doing something immensely stupid and wrong like this:
>>>>>
>>>>> S.request.toList.head.location.toList.head.createDefaultLink.toList.head.text
>>>>>
>>>>> I *know* this is way wrong, but I'm not clever enough, apparently, to
>>>>> figure out the puzzle, despite reading through the Can code repeatedly.
>>>>> I figure the above works only because what I'm looking for is there,
>>>>> which sort of defeats the purpose of the cans...
>>>>>
>>>>> Can anyone help? This is driving me insane.
>>>>>
>>>>> Chas.
>>>>>     
>>>>>         
>>>>   
>>>>       
>>
>>
>>   
> 
> > 

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Lift" group.
To post to this group, send email to liftweb@googlegroups.com
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