Your SlideShare is downloading. ×
Scala jeff
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Scala jeff

2,920
views

Published on


1 Comment
2 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,920
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
64
Comments
1
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. learn in half an hour http://jeffkit.info
  • 2. Scalable language (actor)JVM ,also .net DSL
  • 3. Scala
  • 4. tiobe 2010/1
  • 5. Scala!
  • 6. twitter scala
  • 7. foursquare rogueA Lift/MongoDB Query DSLVenue where (_.mayor eqs 1234) and (_.categories contains “thai”) orderAsc (_.popularity) fetch (10)
  • 8. &Scala
  • 9. Scala
  • 10. Code Time
  • 11. println (“hello Scala”)
  • 12. 1 package info.jeffkit object HelloScala { 2 def main(args : Array[String]) : Unit = { 3 println("hello world") 4 } } 1 2 object -> main 3 4
  • 13. techparty say helloDSL
  • 14. package info.jeffkit1 class Group(val name:String){ def say(msg:String):Unit = { println ("The Group " + this.name + " say : " + msg) } } object HelloScala { def main(args : Array[String]) : Unit = { println("hello scala") 2 val techparty = new Group("techparty") techparty.say("hello scala") 3 techparty say "im the magic of DSL" 4 } } 1 2 3 4 DSL
  • 15. hello
  • 16. 1class Group private (val name:String){ def say(msg:String):Unit = { println ("The Group " + this.name + " say : " + msg) }}object Group{ 2 private val groups = Map( 3 "techparty" -> new Group("techparty"), "barcamp" -> new Group("barcamp"), "openparty" -> new Group("openparty") ) def getGroup(name:String) = {4 if (groups.contains(name)) groups(name) else null }} 1 2 3 Map 4
  • 17. 1def play(game:String,members:Array[Member],perform:Member => Unit) = { println ("The group is playing a game : " + game ) members.foreach{ member => perform(member) 3 } }class Member(val name:String,val topic:String){ def this(name:String){ this(name,null) 2 }}val members = Array( new Member("laiyonghao","male",true,"2010,My choices"), 4 new Member("jeff","male",true,"learn scala in haft an hour"), new Member("iceberg") ) 1 2 3 List foreach 4 List
  • 18. //lambda 1 techparty.play("introduce your self", members, member => println ("My name is " +member.name)) // 2 def present(member:Member) = { if (member.topic != null) println (member.name + " is presenting.") } techparty.play("present", members, present) 3 // , val potluck = techparty.play("potluck", members, _:Member => Unit) potluck(_.name + " is eating") // ============ curry =============== 4 techparty.play_curry("dismiss", members){ member => member.name + " is leaving and going home" } 1 lambda 2 3 4 curry
  • 19. python fans mixin
  • 20. 1 trait Fan{ def like() = "techparty" } trait JavaFan extends Fan{ override def like() = "java " + super.like() } 2 trait PythonFan extends Fan{ override def like() = "python " + super.like() } 3 val member = new Member("jeff","learn scala in haft an hour") with JavaFan with PythonFan 4 member.like() 1 ,trait 2 trait class 3 mixin with) 4 mixin
  • 21. 1def search(condition:Any):String = { 2 condition match { case "sleepy" => println("you look sleepy,sleep 1 second") Thread.sleep(1000) 3 case q:String => println("search by a keyword :" + q) case ("name",name:String) => println("search by name : " + name) case (year:Int,month:Int) => println("search by year " + year +" and " + month) 4 case _ => println("cant handle your search");return "fail" } "success" } 1 2 3 4
  • 22. val receiver = self 1 actor { receiver ! techparty.search("jeff",2010) 2 } 3 val at = actor { receiver ! (self,techparty.search("sleepy")) } println("waiting for actor to finish") 4 for(i <- 1 to 2){ receive { 5 case (at,status:String) => println("hey,at is finish his job,and thestatus is: " + status) case "success" => println("search finish") case "fail" => println("search fail") } } 1 actor 2 3 actor 4 for 4 case
  • 23. Thank you!