[Lift] Re: A stupid question

2008-10-15 Thread Charles F. Munat

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)

This page

Or this:

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

This page

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



[Lift] Re: A stupid question

2008-10-15 Thread Charles F. Munat

Ah, that's a good idea. Didn't think of that.

Chas.

Jorge Ortiz wrote:
> Also check out CanSpec.scala to get an idea of how Cans can be used.
> 
> --j
> 
> On Wed, Oct 15, 2008 at 9:33 AM, David Pollak <[EMAIL PROTECTED] 
> > 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
-~--~~~~--~~--~--~---



[Lift] Re: A stupid question

2008-10-15 Thread Derek Chen-Becker
Charles, to put this in the context of the JPA stuff I'm working on, here's
the pattern I would use for, say, viewing an Author when I have a
corresponding RequestVar:

object passedAuthor extends RequestVar[Can[Author]](Empty)

def view (xhtml : NodeSeq) : NodeSeq = passedAuthor.map({ author =>
  // do bind, etc here and return a NodeSeq
}) openOr Text("Invalid author")

If the RequestVar contains a Full(author) then the map function will be
applied, otherwise the Text node is returned. The map method on Can combined
with openOr makes a very nice pattern for safely processing the contents or
returning a default value. Can's legacyNullTest also helps when you might
get a null back (from a Java library, for instance):

val debug = Can.legacyNullTest(System.getenv("DEBUG_FOO")).map(true) openOr
false

I hope these help.

Derek

On Wed, Oct 15, 2008 at 10:33 AM, David Pollak <[EMAIL PROTECTED]> 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]> <[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
-~--~~~~--~~--~--~---



[Lift] Re: Menu Builder active element

2008-10-15 Thread Bjarte S. Karlsen

Never mind I got it working :)

I will play around with it and ask questions here or in #lift on freenode. 

regards
Bjarte


Bjarte S. Karlsen:
> 
> How do I create a new 0.10-SNAPSHOT project with the mvn archetype?
> 
> regards
> Bjarte
> 
> Bjarte S. Karlsen:
> > 
> > Hello David, 
> > 
> > I am using 0.9 it looks like. But I can upgrade to 0.10-SNAPSHOT tonight and
> > check out this change. The only thing I have done in the project is to try 
> > to
> > adapt the default template so it is no hassle. 
> > 
> > Thanks for the response. I belive it will solve my problem :)
> > 
> > regards, 
> > Bjarte
> > 
> > 
> > David Pollak:
> > > 
> > > Bjarte,
> > > 
> > > What version of Lift are you using?
> > > 
> > > In the current trunk-head (0.10-SNAPSHOT, which I would strongly 
> > > encourage using), you can do:
> > > 
> > > 
> > > 
> > > And the class of the current menu item will be "foo" and the class of 
> > > the 's that are in the breadcrumb path to the item will have the 
> > > class "bar"
> > > 
> > > Thanks,
> > > 
> > > David
> > > 
> > > Bjarte S. Karlsen wrote:
> > > > Helo list, 
> > > >
> > > > Playing around with implementing a already existing design as a lift 
> > > > template. 
> > > >
> > > > The menu of this design requires some way of knowing the menu li 
> > > > element that is the active page. 
> > > > Currently Menu.builder puts to id="current" on the  tag
> > > > and not on the  tag. 
> > > >
> > > > Is this hard to fix? Or if this is not desired to fix this in core, can 
> > > > anybody
> > > > point me to how I can fix it myself? I have not looked much at the lift
> > > > sourceode previously. 
> > > >
> > > >   
> > > 
> > > 
> > > > 
> > > 
> > 
> > -- 
> > With kind regards  / Med vennlig hilsen,
> > Bjarte Stien Karlsen (GPG: 0x626B2F3A)
> > To find out the limits of the possible you have to go beyond them into the
> > impossible.
> > 
> > > 
> > 
> 
> -- 
> With kind regards  / Med vennlig hilsen,
> Bjarte Stien Karlsen (GPG: 0x626B2F3A)
> To find out the limits of the possible you have to go beyond them into the
> impossible.
> 
> > 
> 

-- 
With kind regards  / Med vennlig hilsen,
Bjarte Stien Karlsen (GPG: 0x626B2F3A)
To find out the limits of the possible you have to go beyond them into the
impossible.

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



[Lift] Re: A stupid question

2008-10-15 Thread Jorge Ortiz
Also check out CanSpec.scala to get an idea of how Cans can be used.

--j

On Wed, Oct 15, 2008 at 9:33 AM, David Pollak <[EMAIL PROTECTED]> 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]> <[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
-~--~~~~--~~--~--~---



[Lift] Re: Menu Builder active element

2008-10-15 Thread David Pollak
mvn archetype:create -U  \
 -DarchetypeGroupId=net.liftweb \
 -DarchetypeArtifactId=lift-archetype-basic \
 -DarchetypeVersion=0.10-SNAPSHOT\
 -DremoteRepositories=http://scala-tools.org/repo-snapshots  \
 -DgroupId=net.liftweb.hello -DartifactId=hello-lift



On Wed, Oct 15, 2008 at 9:59 AM, Bjarte S. Karlsen <
[EMAIL PROTECTED]> wrote:

>
> How do I create a new 0.10-SNAPSHOT project with the mvn archetype?
>
> regards
> Bjarte
>
> Bjarte S. Karlsen:
> >
> > Hello David,
> >
> > I am using 0.9 it looks like. But I can upgrade to 0.10-SNAPSHOT tonight
> and
> > check out this change. The only thing I have done in the project is to
> try to
> > adapt the default template so it is no hassle.
> >
> > Thanks for the response. I belive it will solve my problem :)
> >
> > regards,
> > Bjarte
> >
> >
> > David Pollak:
> > >
> > > Bjarte,
> > >
> > > What version of Lift are you using?
> > >
> > > In the current trunk-head (0.10-SNAPSHOT, which I would strongly
> > > encourage using), you can do:
> > >
> > > 
> > >
> > > And the class of the current menu item will be "foo" and the class of
> > > the 's that are in the breadcrumb path to the item will have the
> > > class "bar"
> > >
> > > Thanks,
> > >
> > > David
> > >
> > > Bjarte S. Karlsen wrote:
> > > > Helo list,
> > > >
> > > > Playing around with implementing a already existing design as a lift
> template.
> > > >
> > > > The menu of this design requires some way of knowing the menu li
> element that is the active page.
> > > > Currently Menu.builder puts to id="current" on the  tag
> > > > and not on the  tag.
> > > >
> > > > Is this hard to fix? Or if this is not desired to fix this in core,
> can anybody
> > > > point me to how I can fix it myself? I have not looked much at the
> lift
> > > > sourceode previously.
> > > >
> > > >
> > >
> > >
> > > >
> > >
> >
> > --
> > With kind regards  / Med vennlig hilsen,
> > Bjarte Stien Karlsen (GPG: 0x626B2F3A)
> > To find out the limits of the possible you have to go beyond them into
> the
> > impossible.
> >
> > >
> >
>
> --
> With kind regards  / Med vennlig hilsen,
> Bjarte Stien Karlsen (GPG: 0x626B2F3A)
> To find out the limits of the possible you have to go beyond them into the
> impossible.
>
> >
>


-- 
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

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



[Lift] Re: Menu Builder active element

2008-10-15 Thread Bjarte S. Karlsen

How do I create a new 0.10-SNAPSHOT project with the mvn archetype?

regards
Bjarte

Bjarte S. Karlsen:
> 
> Hello David, 
> 
> I am using 0.9 it looks like. But I can upgrade to 0.10-SNAPSHOT tonight and
> check out this change. The only thing I have done in the project is to try to
> adapt the default template so it is no hassle. 
> 
> Thanks for the response. I belive it will solve my problem :)
> 
> regards, 
> Bjarte
> 
> 
> David Pollak:
> > 
> > Bjarte,
> > 
> > What version of Lift are you using?
> > 
> > In the current trunk-head (0.10-SNAPSHOT, which I would strongly 
> > encourage using), you can do:
> > 
> > 
> > 
> > And the class of the current menu item will be "foo" and the class of 
> > the 's that are in the breadcrumb path to the item will have the 
> > class "bar"
> > 
> > Thanks,
> > 
> > David
> > 
> > Bjarte S. Karlsen wrote:
> > > Helo list, 
> > >
> > > Playing around with implementing a already existing design as a lift 
> > > template. 
> > >
> > > The menu of this design requires some way of knowing the menu li element 
> > > that is the active page. 
> > > Currently Menu.builder puts to id="current" on the  tag
> > > and not on the  tag. 
> > >
> > > Is this hard to fix? Or if this is not desired to fix this in core, can 
> > > anybody
> > > point me to how I can fix it myself? I have not looked much at the lift
> > > sourceode previously. 
> > >
> > >   
> > 
> > 
> > > 
> > 
> 
> -- 
> With kind regards  / Med vennlig hilsen,
> Bjarte Stien Karlsen (GPG: 0x626B2F3A)
> To find out the limits of the possible you have to go beyond them into the
> impossible.
> 
> > 
> 

-- 
With kind regards  / Med vennlig hilsen,
Bjarte Stien Karlsen (GPG: 0x626B2F3A)
To find out the limits of the possible you have to go beyond them into the
impossible.

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



[Lift] *Breaking change* to ajaxButton

2008-10-15 Thread David Pollak
Folks,

I changed the method signature on ajaxButton from ajaxButton(String, =>
JsCmd) to ajaxButton(String, () => JsCmd).  Changing to an explicit function
from a "call by name" makes it clearer that a function is being passed and
also is more friendly to the compiler.

Thanks,

David

-- 
Lift, the simply functional web framework http://liftweb.net
Collaborative Task Management http://much4.us
Follow me: http://twitter.com/dpp
Git some: http://github.com/dpp

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



[Lift] Re: A stupid question

2008-10-15 Thread David Pollak
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
-~--~~~~--~~--~--~---



[Lift] Tools

2008-10-15 Thread Charles F. Munat

One of the hardest parts about learning Lift and Scala is not really 
know what objects look like. Things get pretty complicated and it's 
difficult to remember what's in what.

It would be very nice to be able to step through Lift and see exactly 
what is where in memory and how things change, etc. Normally, I'd use an 
IDE for this. I used to work in C#, and Visual Studio has some very nice 
tools. I can step through the program, look in any variable to see 
what's in it, etc.

In Ruby, I use TextMate. I'm not very good at it, so most of my 
techniques are more rudimentary. But Rails has a nice method called 
debug. I can spit out what's in a variable by just adding:

<%= debug @my_variable %>

to a template. Lift, however, eschews code in templates. I created a 
Test snippet to do the same thing, but I'm having trouble understanding 
reflection in Scala. In Ruby, object.inspect or object.to_yaml can give 
me a pretty good picture of the object.

I've tried Lift in Eclipse, NetBeans, and JEdit and none of them seem to 
work very well. Out of memory errors are common, or I just can't seem to 
get it set up properly.

What tricks are others using to make it easier to see what's going on in 
Lift? Is there a way to step through a request and see exactly what 
happens and in what order? I would kill for that ability.

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



[Lift] Re: A stupid question

2008-10-15 Thread Charles F. Munat

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



[Lift] Re: A stupid question

2008-10-15 Thread David Pollak
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
-~--~~~~--~~--~--~---



[Lift] Re: JPA questions (was Re: SnippetFailure)

2008-10-15 Thread Derek Chen-Becker
Jorge, that's great news! Having to use the classOf definitely felt a little
clunky so this will help clean things up a lot. The "undocumented and
experimental" part scares me a little, but if this will eventually be core
functionality I think we'll definitely move to it.

Thanks,

Derek

On Wed, Oct 15, 2008 at 1:49 AM, Jorge Ortiz <[EMAIL PROTECTED]> wrote:

> Derek,
>
> With the upcoming release of 2.7.2, you can update all this classOf[T]
> stuff to use scala.reflect.Manifest[T], which handles all that stuff for you
> almost automagically.
>
> I've been meaning to blog about this, but haven't found the time. The short
> example is:
>
>   def find[A](id: Any)(implicit m: scala.reflect.Manifest[A]) =
> em.find[A](m.erasure, id).asInstanceOf[A]
>
> Which can be invoked as:
>
>   val user = find[User](userId)
>
> The compiler will fill in the implicit Manifest parameter for you. Manifest
> represents a Scala type. You can test two Manifests for subtype and
> supertype relationships. You can also call "erasure" on a Manifest to get
> the Java Class corresponding to the runtime erasure of that type.
>
> Manifests are undocumented and experimental, so proceed with caution.
> Eventually they'll be the backbone of a native Scala reflection API (yay!)
>
> --j
>
>
> On Tue, Oct 14, 2008 at 6:13 PM, Derek Chen-Becker <[EMAIL PROTECTED]>wrote:
>
>> You can just do Model.find(classOf[User], userId) and the type on the
>> method will be inferred. Any time you see a Class[A] parameter, it wants the
>> result of a classOf[...].
>>
>> Derek
>>
>> On Tue, Oct 14, 2008 at 5:52 PM, Charles F. Munat <[EMAIL PROTECTED]> wrote:
>>
>>>
>>> A question from the JPADemo...
>>>
>>> How does one use this:
>>>
>>> def find[A](clazz: Class[A], id: Any) =
>>>   em.find[A](clazz, id).asInstanceOf[A]
>>>
>>> If I have a User model and I want to use find on the EntityManager, what
>>> goes where the *** is below:
>>>
>>> val user = Model.find[User]( ***, userId)
>>>
>>> Thanks,
>>>
>>> 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
-~--~~~~--~~--~--~---



[Lift] Re: JPA questions (was Re: SnippetFailure)

2008-10-15 Thread Jorge Ortiz
Derek,

With the upcoming release of 2.7.2, you can update all this classOf[T] stuff
to use scala.reflect.Manifest[T], which handles all that stuff for you
almost automagically.

I've been meaning to blog about this, but haven't found the time. The short
example is:

  def find[A](id: Any)(implicit m: scala.reflect.Manifest[A]) =
em.find[A](m.erasure, id).asInstanceOf[A]

Which can be invoked as:

  val user = find[User](userId)

The compiler will fill in the implicit Manifest parameter for you. Manifest
represents a Scala type. You can test two Manifests for subtype and
supertype relationships. You can also call "erasure" on a Manifest to get
the Java Class corresponding to the runtime erasure of that type.

Manifests are undocumented and experimental, so proceed with caution.
Eventually they'll be the backbone of a native Scala reflection API (yay!)

--j

On Tue, Oct 14, 2008 at 6:13 PM, Derek Chen-Becker <[EMAIL PROTECTED]>wrote:

> You can just do Model.find(classOf[User], userId) and the type on the
> method will be inferred. Any time you see a Class[A] parameter, it wants the
> result of a classOf[...].
>
> Derek
>
> On Tue, Oct 14, 2008 at 5:52 PM, Charles F. Munat <[EMAIL PROTECTED]> wrote:
>
>>
>> A question from the JPADemo...
>>
>> How does one use this:
>>
>> def find[A](clazz: Class[A], id: Any) =
>>   em.find[A](clazz, id).asInstanceOf[A]
>>
>> If I have a User model and I want to use find on the EntityManager, what
>> goes where the *** is below:
>>
>> val user = Model.find[User]( ***, userId)
>>
>> Thanks,
>>
>> 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
-~--~~~~--~~--~--~---



[Lift] Re: A stupid question

2008-10-15 Thread Marius

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