SlideShare una empresa de Scribd logo
1 de 26
Descargar para leer sin conexión
learn         in half an hour
        http://jeffkit.info
Scalable language
                   (actor)




JVM   ,also .net
        DSL
Scala
tiobe 2010/1
Scala!
twitter   scala
foursquare                       rogue

A Lift/MongoDB Query DSL



Venue where (_.mayor eqs 1234)
      and (_.categories contains “thai”)
      orderAsc (_.popularity)
      fetch (10)
&Scala
Scala
Code Time
println (“hello Scala”)
1   package info.jeffkit

    object HelloScala {
    2 def main(args : Array[String]) : Unit = {   3
    	   println("hello world") 4
      }
    }


        1


        2                  object -> main
        3


        4
techparty say hello




DSL
package info.jeffkit

1   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 "i'm the magic of DSL" 4
      }
    }

                       1


                       2


                       3


                       4   DSL
hello
1
class 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
1
def   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
//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
python fans   mixin
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
1
def 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("can't handle your search");return "fail"
	 	 }
	 	 "success"
	 }




             1


             2


             3


             4
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 the
status is: " + status)
	    	    	
          case "success" => println("search finish")
	    	    	
          case "fail" => println("search fail")
	    	    }
	     }
                  1  actor

                 2


                 3         actor

                 4   for
                 4                       case
Thank you!

Más contenido relacionado

La actualidad más candente

Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
Loïc Descotte
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
Yardena Meymann
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
djspiewak
 

La actualidad más candente (20)

Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
ハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使うハイブリッド言語Scalaを使う
ハイブリッド言語Scalaを使う
 
Introductionto fp with groovy
Introductionto fp with groovyIntroductionto fp with groovy
Introductionto fp with groovy
 
The TclQuadcode Compiler
The TclQuadcode CompilerThe TclQuadcode Compiler
The TclQuadcode Compiler
 
Scala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar ProkopecScala presentation by Aleksandar Prokopec
Scala presentation by Aleksandar Prokopec
 
Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008Scala at HUJI PL Seminar 2008
Scala at HUJI PL Seminar 2008
 
Intro to Functional Programming in Scala
Intro to Functional Programming in ScalaIntro to Functional Programming in Scala
Intro to Functional Programming in Scala
 
All about scala
All about scalaAll about scala
All about scala
 
Scala vs Ruby
Scala vs RubyScala vs Ruby
Scala vs Ruby
 
Adventures in TclOO
Adventures in TclOOAdventures in TclOO
Adventures in TclOO
 
What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)What can be done with Java, but should better be done with Erlang (@pavlobaron)
What can be done with Java, but should better be done with Erlang (@pavlobaron)
 
Introduction to Scala for Java Developers
Introduction to Scala for Java DevelopersIntroduction to Scala for Java Developers
Introduction to Scala for Java Developers
 
Scala - en bedre Java?
Scala - en bedre Java?Scala - en bedre Java?
Scala - en bedre Java?
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010Starting with Scala : Frontier Developer's Meetup December 2010
Starting with Scala : Frontier Developer's Meetup December 2010
 
Polyglot JVM
Polyglot JVMPolyglot JVM
Polyglot JVM
 
Scala - brief intro
Scala - brief introScala - brief intro
Scala - brief intro
 
Scala fundamentals
Scala fundamentalsScala fundamentals
Scala fundamentals
 

Destacado

Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
pramode_ce
 

Destacado (13)

Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Stairway to scala flyer
Stairway to scala flyerStairway to scala flyer
Stairway to scala flyer
 
Scala for dummies
Scala for dummiesScala for dummies
Scala for dummies
 
Scala Jump Start
Scala Jump StartScala Jump Start
Scala Jump Start
 
Scala for dummies
Scala for dummiesScala for dummies
Scala for dummies
 
Scala vs java 8
Scala vs java 8Scala vs java 8
Scala vs java 8
 
Why Scala for Web 2.0?
Why Scala for Web 2.0?Why Scala for Web 2.0?
Why Scala for Web 2.0?
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Scala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentationScala - The Simple Parts, SFScala presentation
Scala - The Simple Parts, SFScala presentation
 
Advanced Functional Programming in Scala
Advanced Functional Programming in ScalaAdvanced Functional Programming in Scala
Advanced Functional Programming in Scala
 
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
What Is Salesforce CRM? | Salesforce CRM Tutorial For Beginners | Salesforce ...
 
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 

Similar a Scala jeff

pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
Hiroshi Ono
 
Predictably
PredictablyPredictably
Predictably
ztellman
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
Jan Kronquist
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
julien.ponge
 
2.1 recap from-day_one
2.1 recap from-day_one2.1 recap from-day_one
2.1 recap from-day_one
futurespective
 

Similar a Scala jeff (20)

Scala
ScalaScala
Scala
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language여자개발자모임터 6주년 개발 세미나 - Scala Language
여자개발자모임터 6주년 개발 세미나 - Scala Language
 
Scala coated JVM
Scala coated JVMScala coated JVM
Scala coated JVM
 
Scala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereldScala: Functioneel programmeren in een object georiënteerde wereld
Scala: Functioneel programmeren in een object georiënteerde wereld
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
Predictably
PredictablyPredictably
Predictably
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
Clojure for Java developers - Stockholm
Clojure for Java developers - StockholmClojure for Java developers - Stockholm
Clojure for Java developers - Stockholm
 
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 AutumnGoptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
Goptuna Distributed Bayesian Optimization Framework at Go Conference 2019 Autumn
 
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
Java 7 Launch Event at LyonJUG, Lyon France. Fork / Join framework and Projec...
 
Meet scala
Meet scalaMeet scala
Meet scala
 
2.1 recap from-day_one
2.1 recap from-day_one2.1 recap from-day_one
2.1 recap from-day_one
 

Más de jeff kit (11)

构建稳健的iOS推送服务
构建稳健的iOS推送服务构建稳健的iOS推送服务
构建稳健的iOS推送服务
 
Taste Rabbitmq
Taste RabbitmqTaste Rabbitmq
Taste Rabbitmq
 
冲浪 Object-c
冲浪 Object-c冲浪 Object-c
冲浪 Object-c
 
给Geek们的音乐课
给Geek们的音乐课给Geek们的音乐课
给Geek们的音乐课
 
漫游iOS开发指南
漫游iOS开发指南漫游iOS开发指南
漫游iOS开发指南
 
原创音乐会
原创音乐会原创音乐会
原创音乐会
 
杯具是怎样练成的
杯具是怎样练成的杯具是怎样练成的
杯具是怎样练成的
 
Bi
BiBi
Bi
 
Git
GitGit
Git
 
Autoforms
AutoformsAutoforms
Autoforms
 
Brief intro of Dropbox
Brief intro of DropboxBrief intro of Dropbox
Brief intro of Dropbox
 

Scala jeff

  • 1. learn in half an hour http://jeffkit.info
  • 2. Scalable language (actor) JVM ,also .net DSL
  • 6. twitter scala
  • 7. foursquare rogue A Lift/MongoDB Query DSL Venue where (_.mayor eqs 1234) and (_.categories contains “thai”) orderAsc (_.popularity) fetch (10)
  • 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
  • 14. package info.jeffkit 1 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 "i'm the magic of DSL" 4 } } 1 2 3 4 DSL
  • 15. hello
  • 16. 1 class 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.
  • 18. 1 def 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
  • 19. //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
  • 20. python fans mixin
  • 21. 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
  • 22.
  • 23. 1 def 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("can't handle your search");return "fail" } "success" } 1 2 3 4
  • 24.
  • 25. 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 the status is: " + status) case "success" => println("search finish") case "fail" => println("search fail") } } 1 actor 2 3 actor 4 for 4 case