The killer VM language (Hands On)                                          By Romain MATON                                ...
Scala ?   Scripting language   Read / Eval / Print Lopp (REPL) : console interpreter   Run on the JVM   Object Oriented Pr...
Concept  var = mutable variables, val = final Java  Type inference    var myStr:String = « Xebia »    var myStr = « Xebia ...
Some examples… in Scala Console ! var, val                        Array 1::2::3::Nil                    list map array Lis...
Syntax     Object     Class and Case Class     Function declaration     Return is the last closure line (but can use retur...
Syntax : example                   6
Syntax++   Traits FunctionN : apply() with syntaxic sugar ()     Function0[+R]     Function1[-T1, +R] (Function)     …    ...
Higer Order Function                       8
Higer Order Function++                         9
Currying & Partial Functions                               10
List       11
List++         12
List Fury            13
XML      14
Trait   Like Java interface… with code !   Multiple traits for a class with “with” keyword   Add traits on new instance : ...
Trait : mixin composition                            16
Trait : before                 17
Trait : after                18
Pattern Matching   Like Java interface… with code !   Multiple traits for a class with “with” keyword   Add traits on new ...
Pattern Matching : example                             20
Pattern Matching : exception handling                                        21
DSL and RichAPI                  22
DSL and RichAPI : How To                           23
Actors         24
OOP      25
FP     26
FP style in Java…   http://blog.javabien.net/2009/11/02/google-collections-and-enhanced-   javabeans/                     ...
Hands On   GO GO GO !!!   http://www.scala-lang.org/docu/files/api/index.html                                             ...
Upcoming SlideShare
Loading in …5
×

XKE - Hands On Scala

888 views
836 views

Published on

Introduction to Scala with a small Hands On.
Given at Xebia during XKE (November 5th, 2009).

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
888
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
2
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

XKE - Hands On Scala

  1. 1. The killer VM language (Hands On) By Romain MATON November 05th, 2009 www.xebia.fr / blog.xebia.fr
  2. 2. Scala ? Scripting language Read / Eval / Print Lopp (REPL) : console interpreter Run on the JVM Object Oriented Programming Functional Programming Statically typed (Scala needs type !) 100% compatible with Java (objects, interface, generics…) As fast as Java 2
  3. 3. Concept var = mutable variables, val = final Java Type inference var myStr:String = « Xebia » var myStr = « Xebia » Everything is an object ! (or new or invoking method) 1.toString 2 + 4 * 7 = 2.+(4.*(7)) List, Array 1::2::3::Nil = 1.::(2.::(3.::(Nil))) def func(i: Int) = i + 1 Null (AnyRef and AnyVal), Nothing, None 3
  4. 4. Some examples… in Scala Console ! var, val Array 1::2::3::Nil list map array List(1,2,3).map(i=>i*2) HashMap and ScalaHashMap List(1,2,3).map(_+3) myHashMap += 1->“foo” def func(i:Int, j:Int) = i*j (“1”,1)::(“2”,2)::(“3”,3)::Nil List(1,2,3).map(func(_,5)) for(entry <- list) print(“%s %s def func2(i:Int)(j:Int) = i*j %s”, format(p._1,p._2,p._3) List(1,2,3).map(func2(8)) Println {… s} 4
  5. 5. Syntax Object Class and Case Class Function declaration Return is the last closure line (but can use return) Function invocation No parameter : One parameter : Closure 5
  6. 6. Syntax : example 6
  7. 7. Syntax++ Traits FunctionN : apply() with syntaxic sugar () Function0[+R] Function1[-T1, +R] (Function) … Which produce : arr.apply(3)=“foo” => arr(3)=“foo” Higer Order Functions Currying Partial Functions 7
  8. 8. Higer Order Function 8
  9. 9. Higer Order Function++ 9
  10. 10. Currying & Partial Functions 10
  11. 11. List 11
  12. 12. List++ 12
  13. 13. List Fury 13
  14. 14. XML 14
  15. 15. Trait Like Java interface… with code ! Multiple traits for a class with “with” keyword Add traits on new instance : trait foo { def f(i;Int) = I } class person person p = new person with foo p.f(3) (or p f 3 ☺) 15
  16. 16. Trait : mixin composition 16
  17. 17. Trait : before 17
  18. 18. Trait : after 18
  19. 19. Pattern Matching Like Java interface… with code ! Multiple traits for a class with “with” keyword Add traits on new instance : trait foo { def f(i;Int) = I } class person person p = new person with foo p.f(3) (or p f 3 ☺) 19
  20. 20. Pattern Matching : example 20
  21. 21. Pattern Matching : exception handling 21
  22. 22. DSL and RichAPI 22
  23. 23. DSL and RichAPI : How To 23
  24. 24. Actors 24
  25. 25. OOP 25
  26. 26. FP 26
  27. 27. FP style in Java… http://blog.javabien.net/2009/11/02/google-collections-and-enhanced- javabeans/ 27
  28. 28. Hands On GO GO GO !!! http://www.scala-lang.org/docu/files/api/index.html 28

×