SlideShare ist ein Scribd-Unternehmen logo
1 von 60
Introduction toCoding in Scala is fun!,[object Object],OOP 2010,[object Object],Dr. Michael Stal,[object Object],Michael.Stal@siemens.com,[object Object]
Objectives of this Presentation,[object Object],Introduce core concepts of Scala,[object Object],Showing you the benefits of combining OO with functional programming,[object Object],Illustrating the language in a pragmatic way preferring code over theory,[object Object],But not to cover every available aspect or to cover aspects in full  detail,[object Object],For instance, we won‘t cover Java/Scala Interop, Views, Equality Semantics, Unit Testing, Annotations,[object Object],Page 2,[object Object]
Introduction,[object Object],Scala created by the team of Martin Odersky at EPFL,[object Object],„Scala“ means „Scalable Language“,[object Object],„Scalable“ means: ,[object Object],the same language concepts for programming in the small & large,[object Object],In Scala this is achieved in a pragmatic way by combining ,[object Object],Object Oriented Programming with,[object Object],Functional Programming ,[object Object],Scala is a statically typed language like Java,[object Object],All types are objects,[object Object],Page 3,[object Object],Martin Odersky, Source: http://lamp.epfl.ch/~odersky/,[object Object]
Object-Oriented & Functional Programming,[object Object],Object-Oriented Programming,[object Object],Abstraction using Classes and Interfaces,[object Object],Refinement using subtyping and inheritance (Remember the Liskov Substitution Principle!),[object Object],Dynamics through polymorphism,[object Object],Functional Programming,[object Object],Higher Order Functions as First-Class Entities,[object Object],ADTs (Abstract Data Types) following algebraic conventions,[object Object],Pattern matching,[object Object],Parametric polymorphism (generic types),[object Object],Page 4,[object Object],SCALA,[object Object]
Core Properties of Scala (see Programming in Scala),[object Object],Scala is compatible: runs on JVM, interoperability with Java,[object Object],Scala is concise: More compact code because removal of Java boilerplate code and powerful libraries,[object Object],Scala is high-level: Higher level of abstraction by combining OO with functional programming,[object Object],Scala is statically typed,[object Object],Page 5,[object Object],Scala‘s Roots:,[object Object],[object Object]
 Smalltalk, Ruby
 Beta, Simula, Algol
 ML
 Erlang,[object Object]
Stairway to Heaven – First Steps using Scala ,[object Object],This source code file may be compiled using scalac und run using scala:,[object Object],scalac HelloWorldMain.scala,[object Object],scala HelloWorldMain ,[object Object],Note: the source file must be named like the main object to be executed ,[object Object],You may run an interpreter by using the following command line instead,[object Object],scala HelloWorldMain.scala ,[object Object],In this case you may also use plain Scala scripts (no classes or objects required),[object Object],Or, even better, you might use an IDE like Idea, Netbeans, or Eclipse,[object Object],Page 7,[object Object]
A more advanced example (1)  (from Venkat Subramanian‘s book Programming Scala, pp.5),[object Object],Page 8,[object Object],import scala.actors._,[object Object],import Actor._,[object Object],val symbols = List( "AAPL", "GOOG", "IBM", "JAVA", "MSFT"),[object Object],val receiver = self,[object Object],val year = 2009,[object Object],symbols.foreach { ,[object Object],  symbol =>  actor { receiver ! getYearEndClosing(symbol, year) },[object Object],},[object Object],val (topStock, highestPrice) = getTopStock(symbols.length),[object Object],printf("Top stock of %d is %s closing at price %f", year, topStock, highestPrice),[object Object],def getYearEndClosing(symbol : String, year : Int) = {  ,[object Object],  val url = new   ,[object Object],    java.net.URL("http://ichart.finance.yahoo.com/table.csv?s=" +,[object Object],    symbol + "&a=11&b=01&c=" + year + "&d=11&e=31&f=" + year + "&g=m")      ,[object Object],  val data = io.Source.fromURL(url).mkString  ,[object Object],  val price = data.split("")(1).split(",")(4).toDouble    ,[object Object],  (symbol, price),[object Object],} // .. to be continued,[object Object]
A more advanced example (2)(from Venkat Subramanian‘s book Programming Scala, pp.5),[object Object],Run this within interpreter mode scala TopScala.scala,[object Object],After the end of the talk return to this example and check whether you better understand it,[object Object],Page 9,[object Object],// continued ...,[object Object],def getTopStock(count : Int) : (String, Double) = {  ,[object Object],   (1 to count).foldLeft("", 0.0) { (previousHigh, index) =>    ,[object Object],     receiveWithin(10000) {      ,[object Object],       case (symbol : String, price : Double) =>        ,[object Object],           if (price > previousHigh._2) (symbol, price) ,[object Object],           else previousHigh    ,[object Object],     }  ,[object Object],   },[object Object],} ,[object Object],// will result in =>,[object Object],// Top stock of 2009 is GOOG closing at price 619,980000,[object Object]
Scala Type Hierarchy,[object Object],Page 10,[object Object],Scala uses a pure object-oriented type system,[object Object],Every value is an object,[object Object],Two types: values and references,[object Object],Any is parent class of all classes, Nothing subclass of all classes,[object Object],Basic,[object Object],types like in,[object Object],Java,[object Object],Source: Scala Reference Manual,[object Object]
First Class Scala,[object Object],Page 11,[object Object],born and ,[object Object],id will be,[object Object],public fields,[object Object],Main constructor,[object Object],Classes in Scala contain fields, methods, types, constructors,[object Object],Visibility is public per default,[object Object],class CatID(val id : Int)  //that's a whole class,[object Object],class Cat(val born: Int, val id: CatID) {,[object Object],private var miceEaten: Int = 0,[object Object],   def digested() = miceEaten,[object Object],def hunt(miceCaught: Int) ,[object Object],             { miceEaten +=  miceCaught },[object Object],},[object Object],object ScalaClasses {,[object Object],   def main(args: Array[String]) {,[object Object],     val id = new CatID(42),[object Object],     val tom = new Cat(2010, id),[object Object],     tom.hunt(3),[object Object],     tom hunt 2,[object Object],     println(“cat was born in “ + tom.born) ,[object Object],     println(tom.digested),[object Object],   },[object Object],} // => 5 <> Tom was born in 2010 ,[object Object],definition,[object Object],of methods,[object Object],No brackets,[object Object],required,[object Object]
Class Constructors,[object Object],Page 12,[object Object],class Complex (r : Double, i: Double) {,[object Object],  println("Constructing a complex number"),[object Object],  val re = r,[object Object],  val im = i,[object Object],  def this(r : Double) = this(r,0),[object Object],  override def toString =  ,[object Object],       re + (if (im < 0) "-" + (-im) ,[object Object],             else "+" + im) + "*i",[object Object],  ...,[object Object],},[object Object],Belongs to,[object Object],Primary,[object Object],constructor,[object Object],Auxilliary,[object Object],constructorsmust call,[object Object],primary,[object Object]
Immutable and Mutable Objects,[object Object],Scala provides immutable objects (functional programming) but also mutable objects,[object Object],Immutability has many benefits,[object Object],Reduction of race conditions in concurrent programs,[object Object],Protection against unwanted modification,[object Object],Scala provides mutable & immutable versions of collection types,[object Object],Mutable objects are important to address objects that are supposed to change their state, but use them with care,[object Object],Page 13,[object Object],class Person(var name: String),[object Object],object ImmutabilityDemo {,[object Object], def main(args:Array[String]) = {,[object Object],val s = "Michael",[object Object],   s = "Bill" // error,[object Object],var t = "Michael“ // t variable,[object Object],   t = "Bill" // ok,[object Object],   val c = new Person("Bill"),[object Object],   c = new Person("Tom") // error,[object Object],// ok - c itself unchanged:,[object Object],   c.name = "Tom",[object Object], },[object Object],},[object Object]
Inheritance,[object Object],In Scala classes can be derived from at most one base class,[object Object],Classes may be abstract,[object Object],You need to indicate whether you override inherited methods,[object Object],Page 14,[object Object],abstractclass Shape {,[object Object],type Identifier = Int // defining types,[object Object],  def getID() : Identifier = 42,[object Object],  def draw() : String   // abstract method,[object Object],},[object Object],class Circle (val cx: Double, val cy: Double, val r: Double) extends Shape {,[object Object],  val id : Identifier = getID(),[object Object],override def draw() : String = "I am a Circle",[object Object],},[object Object]
Companion Objects and Standalone Objects,[object Object],We already saw standalone objects,[object Object],Objects are singletons,[object Object],If you need static fields or methods for a class, introduce a companion class with the same name,[object Object],Convention: apply() methods may be provided as factory methods,[object Object],Page 15,[object Object],class Cat private (val born : Int, val id: CatID) {,[object Object],   ...,[object Object],private def this(id: CatID) = this(2010, id),[object Object],   ...,[object Object],} // all constructors are private,[object Object],object Cat { // this is the companion object of Cat,[object Object],def apply(born: Int, id: CatID) =  new Cat(born, id),[object Object],   def apply(id: CatID) = new Cat(id) // factory method,[object Object],   def whatCatsDo() = "Sleep, eat, play"	,[object Object],},[object Object],object ScalaClasses { // Standalone Object,[object Object],   def main(args: Array[String]) {,[object Object],     val id = new CatID(43),[object Object],val pussy = Cat(id) // no new required,[object Object],     println("Pussy was born in " + pussy.born),[object Object],     println(Cat.whatCatsDo)  // like static in Java  ,[object Object],   },[object Object],},[object Object]
Application Base Class,[object Object],For experimenting with Scala use the base class Application,[object Object],Just compile this with: scalac ObjDemo.scala,[object Object],And run it with: scala ObjDemo,[object Object],Useful abbreviation if you do not need to deal with command line arguments,[object Object],Page 16,[object Object],  Inheritance,[object Object],object ObjDemoextends Application {,[object Object],val s: String = "Michael",[object Object],println(s) // => Michael,[object Object],},[object Object]
Traits,[object Object],Classes and instances may mix-in additional functionality using traits,[object Object],Traits represent an abstraction between interfaces and classes,[object Object],Using traits we can easily live with the single-inheritance restriction,[object Object],You may use also traits via anonymous classes:,[object Object],	val x = new Identity{},[object Object],  	x.name = "UFO",[object Object],  	println(x.whoAmI),[object Object],Page 17,[object Object],trait   Identity  {,[object Object],   var name: String="",[object Object],   def whoAmI() : String = name	,[object Object],},[object Object],class  Person extends Identity ,[object Object],class Animal,[object Object],object TraitDemo {,[object Object], def main(args:Array[String]) = {,[object Object],   val p = new Person,[object Object],   p.name = "Michael",[object Object],   println(p.whoAmI),[object Object],val a = new Animal with Identity,[object Object],   a.name = "Kittie",[object Object],   println(a.whoAmI),[object Object], },[object Object],} // => Michael <> Kittie,[object Object]
Traits and Virtual Super: Inheritance Linearization,[object Object],Page 18,[object Object],abstract class Processor { def process() },[object Object],trait Compressor extends Processor { // trait only applicable to Processor subclass,[object Object],abstract override def process() =  { println("I am compressing"); super.process },[object Object],},[object Object],trait Encryptor extends Processor { // only applicable to Processor subclass,[object Object],abstract override def process() = { println("I am encrypting"); super.process},[object Object],},[object Object],class SampleProcessor extends Processor { // subclass of Processor,[object Object],    override def process() = println("I am a Sample Processor"),[object Object],},[object Object],object traitsample2 {,[object Object],    def main(args:Array[String]) = { // mixing in a trait to an object:,[object Object],val proc1 = new SampleProcessor with Compressor with Encryptor,[object Object],proc1.process// Encryptor.process=>Compressor.process,[object Object],     }                        //                                   => SampleProcessor.process,[object Object],},[object Object],Note: abstract override for a trait method means the actual subclass of Processor will provide a concrete implementation of that method!,[object Object]
Scala Basics: if Statements,[object Object],If statements are expressions themselves, i.e. they have values,[object Object],Page 19,[object Object],import java.util._,[object Object],if (1 + 1 == 3) ,[object Object],println(“strange world”) ,[object Object],else {,[object Object],println(“everything’s ok”),[object Object],},[object Object],val res = if ((new Random().nextInt(6) + 1) == 6) ,[object Object],		"You win!" ,[object Object],	    else ,[object Object],            "You lose!",[object Object]
Scala Basics: for Comprehensions (1),[object Object],A for comprehension is like a for loop. It lets you traverse a collection, return every object in a temporary variable which is then passed to an expression. You may also specify nested iterations:,[object Object],You can specify filters for the collection elements,[object Object],Page 20,[object Object],val aList  = List(1,2,3,4,5,6),[object Object],for (i <- aList) println(i) // => 1 <> 2 ...,[object Object],val dogs = Set("Lassie", "Lucy", "Rex", "Prince");,[object Object],for (a <- dogs if a.contains("L")) println(a),[object Object],// => “Lassie” <> “Lucy”,[object Object]
Scala Basics: for Comprehensions (2),[object Object],Yield allows to create new collections in a for comprehension:,[object Object],You can specify filters for the collection elements,[object Object],Page 21,[object Object],var newSet = for { ,[object Object],                  a <- dogs ,[object Object],                  if a.startsWith("L"),[object Object],             } yield a,[object Object],println(newSet)  // Set(Lassie, Lucy),[object Object],for { ,[object Object],    i <- List(1,2,3,4,5,6),[object Object],    j = i * 2 // new variable j defined,[object Object],} println(j) // => 2 <> 4 <> 6 ...,[object Object]
Scala Basics: Other loops,[object Object],Scala supports while and do-while loops,[object Object],But generator expressions such as (1 to 6)  incl. 6 or (1 until 6) excl. 6 together with for make this much easier,[object Object],Note: The reason this works is a conversion to RichInt where to is defined as a method that returns an object of type Range.Inclusive, an inner class of Range implementing for comprehensions,[object Object],Page 22,[object Object],var i = 1,[object Object],while (i <= 6)  {,[object Object],    println(i),[object Object],    i  += 1,[object Object],} // = 1 <> 2 <> 3 ...,[object Object], for (i <- 1 to 6) println(i),[object Object]
Scala Basics: Exception handling,[object Object],try-catch-finally available in Scala but throws isn‘t,[object Object],catching checked exceptions is optional!,[object Object],catch-order important as in Java, C++ or C#,[object Object],Page 23,[object Object],def temperature(f: Double) {,[object Object],  if (f < 0) throw new IllegalArgumentException(),[object Object],},[object Object],try {,[object Object],   println("acquiring resources"),[object Object],   temperature(-5),[object Object],},[object Object],catch {,[object Object],   case ex:  IllegalArgumentException => println("temperatur < 0!"),[object Object],   case _ => println("unexpected problem"),[object Object],},[object Object],finally {,[object Object],   println("releasing resources"),[object Object],} ,[object Object]
Inner Classes,[object Object],You may define inner classes as in Java,[object Object],Special notation (<name> =>)  for referring to outer class this from an inner class: you might also use <outerclass>.this instead,[object Object],Page 24,[object Object],class Element (val id: String){ elem =>,[object Object],class Properties { // inner class,[object Object],type KV = Tuple2[String, Any],[object Object],    var props: List[KV] = Nil,[object Object],    def add(entry: KV) { props = entry :: props },[object Object],    override def toString = {,[object Object],      var s: String = "",[object Object],      for (p <- properties.props) s = s + p +"",[object Object],      s,[object Object],    },[object Object],},[object Object],  override def toString = "ID = " + id + "" + properties,[object Object],  val properties = new Properties  ,[object Object],},[object Object],object InnerClassDemo extends Application {,[object Object],  val e = new Element("Window"),[object Object],  e.properties.add("Color", "Red"),[object Object],  e.properties.add("Version", 42),[object Object],  println(e.toString),[object Object],},[object Object]
Imports and Packages,[object Object],We can partition Scala definitions into packages:,[object Object],A package is a special object which defines a set of member classes, objects and packages. Unlike other objects, packages are not introduced by a definition,[object Object],Importing packages works via import statements – almost like in Java,[object Object],Packages scala, java.lang, scala.Predefare automatically imported,[object Object],Page 25,[object Object],package MyPackage1 {,[object Object],   class Person(val name: String),[object Object],   class Animal(val name: String),[object Object],},[object Object],import MyPackage1._,[object Object],object PacDemo extends Application {,[object Object],   val person = new Person("Michael"),[object Object],   println(person name),[object Object],},[object Object],[object Object],                                  to import p.* in Java). ,[object Object],[object Object]
 import p.{x => a}   the member x of p renamed as a.
 import p.{x, y}       the members x and y of p.
 import p1.p2.z       the member z of p2, itself member of p1.,[object Object]
Advanced Types: Sets,[object Object],Collection Type: Set,[object Object],Page 27,[object Object],object SetDemo {,[object Object], def main(args:Array[String]) {,[object Object],val s1 = Set[Int](1,2,3,4,5) // we could also use = Set(1,2,3,4,5),[object Object],val s2 = Set[Int](2,3,5,7),[object Object],println(s2.contains(3))  // => true,[object Object],val s3 = s1 ++ s2 // union,[object Object],println(s3) // => Set(5,7,3,1,4,2),[object Object],vals4 = s1 & s2 // intersection: in earlier versions **,[object Object],println(s4) // Set(5,3,2) ,[object Object], },[object Object],},[object Object]
Advanced Types: Maps,[object Object],Collection Type: Map,[object Object],Page 28,[object Object],object MapDemo {,[object Object], def main(args:Array[String]) {,[object Object],val m1 = Map[Int, String](1 -> "Scala", 2->"Java", 3->"Clojure"),[object Object],valm2 = m1 + (4 -> "C#") // add entry,[object Object],println(m2 + " has size " + m2.size) ,[object Object],                           //=> Map(1->Scala,…) has size 4,[object Object],println(m1(1)) // => Scala,[object Object],val m3 = m2 filter { element => val (key, value) = element,[object Object],                    (value contains "a") }  ,[object Object],println(m3) // => Map(1->Scala, w->Java),[object Object], },[object Object],},[object Object]
Advanced Types: Options,[object Object],object DayOfWeek extends Enumeration {,[object Object],  val Monday    = Value("Monday") //argument optional ,[object Object],  val Sunday    = Value("Sunday") //argument optional ,[object Object],},[object Object],import DayOfWeek._ ,[object Object],object OptionDemo {,[object Object], def whatIDo(day: DayOfWeek.Value) : Option[String] =    ,[object Object], {,[object Object],    day match {,[object Object],      case Monday  => Some("Working hard"),[object Object],      case Sunday  => None,[object Object],    },[object Object], },[object Object], def main(args:Array[String]) {,[object Object],   println(whatIDo(DayOfWeek.Monday)) ,[object Object],   println(whatIDo(DayOfWeek.Sunday)) ,[object Object], } //=> Some(„Working Hard“) <> None,[object Object],},[object Object],The Option type helps dealing with optional values,[object Object],For instance, a search operation might return  a result or nothing,[object Object],We are also introducing Enumerationtypes,[object Object],Page 29,[object Object]
Advanced Types: Regular Expressions,[object Object],Type: Regex introduces well-known regular expressions,[object Object],Page 30,[object Object],With this syntax strings remain formatted as specified and escape sequences are not required,[object Object],object RegDemo {,[object Object], def main(args:Array[String]) {,[object Object],val pattern = """""".r,[object Object],val sentence = “X was born on 01.01.2000 ?",[object Object],println (pattern findFirstIn sentence) // => Some(01.01.2000),[object Object], },[object Object],},[object Object],Note: the „r“ in “““<string>“““.r means: regular expression,[object Object]
Advanced Types: Tuples,[object Object],Tuples combine fixed number of Elements of various types,[object Object],Thus, you are freed from creating heavy-weight classes for  simple aggregates,[object Object],Page 31,[object Object],println( (1, "Douglas Adams", true) ),[object Object],def goodBook = {,[object Object],("Douglas Adams", 42, "Hitchhiker's Guide"),[object Object],}        ,[object Object],println ( goodBook._3 ) // get third element,[object Object],// => (1, Douglas Adams, true),[object Object],// => Hitchhiker‘s Guide,[object Object]
Advanced Types: Arrays,[object Object],Arrays hold sequences of elements,[object Object],Access very efficient,[object Object],Page 32,[object Object],val a1 = new Array[Int](5) // initialized with zeros ,[object Object],val a2 = Array(1,2,3,4,5) // initialized with 1,2,3,4,5,[object Object],println( a2(1) ) // => 2,[object Object],a2(1) = 1 // => Array (1,1,3,4,5),[object Object],Note:,[object Object],In Scala the assignment operator = does not return a reference to the left variable (e.g., in a = b).,[object Object],Thus, the following is allowed in Java but not in Scala: a = b = c  ,[object Object]
Smooth Operator,[object Object],In Scala operator symbols are just plain method names ,[object Object],For instance 1 + 2 stands for 1.+(2),[object Object],Precedence rules:,[object Object],All letters,[object Object],|,[object Object],^,[object Object],&,[object Object],<  >,[object Object],=  !,[object Object],:,[object Object],+  -,[object Object],*  /  %,[object Object],Page 33,[object Object],class Complex(val re:Double, val im:Double) {,[object Object],def +(that: Complex) : Complex = {,[object Object],     new Complex(this.re + that.re, ,[object Object],                 this.im + that.im),[object Object],   },[object Object],   override def toString() : String = {,[object Object],     re + (if (im < 0) "" else "+") + im +"i",[object Object],   },[object Object],},[object Object],object Operators {,[object Object],  def main(args: Array[String]) {,[object Object],        val c1 = new Complex(1.0, 1.0),[object Object],        val c2 = new Complex(2.0, 1.0),[object Object],        println(c1+c2),[object Object],  },[object Object],} // => (3.0+2.0i),[object Object]
Conversions,[object Object],Implicit converters allow Scala to automatically convert data types,[object Object],Suppose, you‘d like to introduce a mathematical notatation such as 10! ,[object Object],Using implicit type converters you can easily achieve this,[object Object],Page 34,[object Object],object Factorial {,[object Object],  def fac(n: Int): BigInt =,[object Object],    if (n == 0) 1 else fac(n-1) * n,[object Object],  class Factorizer(n: Int) {,[object Object],def ! = fac(n),[object Object],  },[object Object],implicit def int2fac(n: Int) = new Factorizer(n),[object Object],},[object Object],import Factorial._,[object Object],object ConvDemo extends Application {,[object Object],println("8! = " + (8!)) // 8 will be implicitly converted,[object Object],} // => 40320,[object Object]
Parameterized Types in Scala,[object Object],Classes, Traits, Functions may be parameterized with types,[object Object],In contrast to Java no wildcards permitted – parameter types must have names,[object Object],Variance specification allow to specify covariance and contravariance,[object Object],Page 35,[object Object],trait MyTrait[S,T] {,[object Object],  def print(s:S, t:T) : String = "(" + s  + "," + t + ")",[object Object],},[object Object],class MyPair[S,T] (val s : S, val t : T) ,[object Object],extends MyTrait [S,T] {,[object Object],  override def toString() : String = print(s,t)	,[object Object],},[object Object],object Generics {,[object Object],  def main(args: Array[String]) {,[object Object],	val m = new MyPair[Int,Int](1,1),[object Object],	printf(m.toString()),[object Object],  },[object Object],} // => (1,1),[object Object]
Small Detour to Variance and Covariance / Type Bounds,[object Object],If X[T] is a parameterized type and T an immutable type:,[object Object],X[T] is covariant in T if:	S subTypeOf T => X[S] subTypeOf  X[T],[object Object],X[T] is contravariant in T if:  	S subTypeOf T => X[S] superTypeOf X[T],[object Object],In Scala covariance is expressed as X[+T] and contravariance with X[-T],[object Object],Covariance is not always what you want: Intuitively we could assign a set of apples to a set of fruits. However, to a set of fruits we can add an orange.  The original set of apples gets „corrupted“ this way,[object Object],Example List[+T]: Covariance means a List[Int] can be assigned to a List[Any] because Int is subtype of Any,[object Object],Upper/Lower Bounds may be specified:,[object Object],In the following example D must be supertype of S:,[object Object],	def copy[S, D>:S](src: Array[S], dst: Array[D]) = { ...,[object Object],Page 36,[object Object]
Functional Aspects: Functions and Closures,[object Object],In Scala Functions are First-Class Citizens,[object Object],They can be ,[object Object],passed as arguments,[object Object],assigned to variables:           val closure={i:Int => i+42},[object Object],Nested functions are also supported,[object Object],Page 37,[object Object],object scalafunctions {,[object Object],  def add(left:Int,right:Int, code:Int=>Int)=,[object Object],  {,[object Object],var res = 0,[object Object],     for (i<-left to right) res += code(i),[object Object],     res,[object Object],  },[object Object],  def main(args: Array[String]) {,[object Object],println(add(0,10, i => i)),[object Object],println(add(10,20, i => i % 2  )),[object Object],  },[object Object],},[object Object],=>,[object Object],55,[object Object],5,[object Object]
Functional Aspects: Call-by-Name,[object Object],If a parameterless closure is passed as an argument to a function, Scala will evaluate the argument when the argument is actually used,[object Object],This is in contrast to call-by-value arguments,[object Object],A similar effect can be achieved using lazy (value) evaluation:     ,[object Object],lazy val = <expr>       ,[object Object],Page 38,[object Object],import java.util._,[object Object],object CbNDemo {,[object Object],def fun(v: => Int) : Int = v ,[object Object], // v is a Call-by-Name Parameter,[object Object],def v() : Int = new Random().nextInt(1000),[object Object], def main(args:Array[String]) {,[object Object],   println( fun(v) ),[object Object],   println( fun(v) )  ,[object Object], },[object Object],} // => 123 <> 243,[object Object]
Functional Aspects: Currying (1),[object Object],Currying means to transform a function with multiple arguments to a nested call of functions with one (or more) argument(s),[object Object],def fun(i:Int)(j:Int) {},[object Object],   (Int)=>(Int)=>Unit=<function1>,[object Object],Page 39,[object Object],object scalafunctions {,[object Object],   def fun1(i:Int, j:Int) : Int = i + j,[object Object],def fun2(i:Int)(j:Int) : Int = i + j  ,[object Object],   def main(args: Array[String]) {,[object Object],	println(fun1(2,3)),[object Object],	println(fun2(2){3}),[object Object],	println(fun2{2}{3} ),[object Object],   },[object Object],}  // => 5 5 5,[object Object]
Functional Aspects: Currying (2),[object Object],Currying helps increase readability,[object Object],Take foldleft as an example,[object Object],Page 40,[object Object],FoldLeft Operator,[object Object],val x =  (0 /: (1 to 10)) { (sum, elem) => sum + elem } // 55 ,[object Object],Carryover value for next iteration,[object Object],Function arguments,[object Object],Carryover value,[object Object],Collection,[object Object],For each iteration, foldleft passes the carry over value and the current collection element. We need to provide the operation to be applied,[object Object],This is collection which we iterate over,[object Object],This is the value that is updated in each iteration,[object Object],Think how this would be implemented in Java!,[object Object]
Positional Parameters,[object Object],If you use a parameter only once, you can use positional notation of parameters with _ (underscore) instead,[object Object],Page 41,[object Object],object scalafunctions {,[object Object], def main(args:Array[String]) {,[object Object],	val seq= (1 to 10),[object Object],	println( (0 /: seq) { (sum, elem) => sum + elem } ),[object Object],	println( (0 /: seq) { _ + _ } ),[object Object],  }	,[object Object],},[object Object]
Using the features we can build new DSLs and additional features easily,[object Object],The following loop-unless example is from the Scala tutorial ,[object Object],Page 42,[object Object],object TargetTest2 extends Application {,[object Object],def loop(body: => Unit): LoopUnlessCond =,[object Object],    new LoopUnlessCond(body),[object Object],protected class LoopUnlessCond(body: => Unit) {,[object Object],    def unless(cond: => Boolean) {,[object Object],      body,[object Object],      if (!cond) unless(cond),[object Object],    },[object Object],  },[object Object],  var i = 10 ,[object Object],  loop {,[object Object],    println("i = " + i),[object Object],    i -= 1,[object Object],  } unless (i == 0),[object Object],},[object Object],We are calling loop,[object Object],with this body ...,[object Object],and invoking unless,[object Object],on the result,[object Object]
Functional Aspect: Partially Applied Functions,[object Object],If you only provide a subset of arguments to a function call, you actually retrieve a partially defined function,[object Object],Only the passed arguments are bound, all others are not,[object Object],In a call to a partially applied function you need to pass the unbound arguments,[object Object],All this is useful to leverage the DRY principle when passing the same arguments again and again,[object Object],Page 43,[object Object],object scalafunctions {,[object Object],  def fun(a : Int, b : Int, c:Int) = a+b+c,[object Object],  def main(args: Array[String]) {,[object Object],val partialFun = fun(1,2,_:Int),[object Object],	  println( partialFun(3) ) // 6,[object Object],	  println( partialFun(4) ) // 7,[object Object],	},[object Object],},[object Object]
Functions Are Objects,[object Object], Function: S => T,[object Object], trait Function1[-S,+T] {,[object Object],     def apply(x:S):T,[object Object],   },[object Object],Example: ,[object Object], (x: Int) => x * 2,[object Object],-> new Function1[Int,Int] {,[object Object],     def apply(X:Int):Int = x * 2,[object Object],   },[object Object],In Scala all function values are objects,[object Object],Basically, each function is identical to a class with an apply method,[object Object],Thus, you can even derive subclasses from functions,[object Object],Array is an example for this: ,[object Object],class Array [T] (length: Int ) ,[object Object],extends (Int => T)  {,[object Object],def length: Int = ...,[object Object],Page 44,[object Object]
Functional Aspects: Pattern Matching,[object Object],Pattern matching allows to make a  pragmatic choice between various options,[object Object],Page 45,[object Object],valaNumber = new Random().nextInt(6) + 1;,[object Object],aNumbermatch {,[object Object],case 6 => println("You got a 6"),[object Object],case 1 => println("You got a 1");,[object Object],caseotherNumber => println("It is a " + otherNumber),[object Object],}	,[object Object]
Functional Aspects: Matching on Types,[object Object],It is also possible to differentiate by type:,[object Object],Page 46,[object Object],object TypeCase {,[object Object],   def matcher(a: Any) {,[object Object],a match {,[object Object],	   case i : Int if (i == 42) => println("42"),[object Object],	   case j : Int => println("Another int"),[object Object],	   case s : String => println(s),[object Object],	   case _  => println("Something else"),[object Object],        },[object Object],   },[object Object],   def main(args: Array[String]) {,[object Object],	matcher(42),[object Object],	matcher(1),[object Object],	matcher("OOP"),[object Object],	matcher(1.3)	,[object Object],   },[object Object],} // => 41 <> 1  <> OOP <> Something else,[object Object]
Functional Aspects: Matching on Lists,[object Object],Lists can be easily used with Pattern Matching:,[object Object],Page 47,[object Object],object ListCase {,[object Object],   def matcher(l: List[Int]) {,[object Object],l match {,[object Object],	   case List(1,2,3,5,7) => println("Primes"),[object Object],	   case List(_,_,_3,_) => println("3 on 3");,[object Object],	   case 1::rest => println("List with starting 1");,[object Object],	   case List(_*) => println("Other List");,[object Object],        },[object Object],   },[object Object],   def main(args: Array[String]) {,[object Object],	matcher(List(1,2,3,5,7)),[object Object],	matcher(List(5,4,3,2)),[object Object],	matcher(List(1,4,5,6,7,8));,[object Object],	matcher(List(42)),[object Object],   },[object Object],} => Primes <> 3 on 3 <> List with starting 1 <> Other List,[object Object]
Functional Aspects: Matching on Tuples,[object Object],So do Tuples:,[object Object],Page 48,[object Object],object TupleCase {,[object Object],   def matcher(t : Tuple2[String,String]) {,[object Object],t match {,[object Object],	   	case ("OOP",s) => println("OOP " + s),[object Object],  		case ("Scala", s) => println("Scala " + s),[object Object],	   	case _ => println("Other Tuple"),[object Object],        },[object Object],   },[object Object],   def main(args: Array[String]) {,[object Object],	matcher("OOP", "2010"),[object Object],	matcher("Scala", "rocks");,[object Object],	matcher("A","B"),[object Object],   },[object Object],} => OOP 2010 <> Scala rocks >cr> Other Tuple,[object Object]
Functional Aspects: Matching on Case Classes,[object Object],Case Classes are classes for which the compiler generates additional functionality to enable pattern matching, e.g., an apply() method:,[object Object],Page 49,[object Object],sealed abstract class Shape // sealed => subclasses only in this source file,[object Object],case class Circle(val center: Point, val radius: Double) extends Shape,[object Object],case class Line(val pt1: Point, val pt2: Point) extends Shape,[object Object],case class Point (val x:Double, val y:Double){,[object Object],   override def toString() = "(" + x +"," + y + ")" },[object Object],object CaseClasses {,[object Object],   def matcher(s : Shape) {,[object Object],s match {,[object Object],	   case Circle(c, r) => println(“Circle“ :  + c +  “ “ + r),[object Object],	   case Line(p1, p2) => println("Line " + p1 + " : " + p2) ,[object Object],	   case _ => println("Unknown shape"),[object Object],        },[object Object],   },[object Object],   def main(args: Array[String]) {,[object Object],	matcher(Circle(Point(1.0, 1.0), 2.0)),[object Object],	matcher(Line(Point(1.0, 1.0), Point(2.0, 2.0))),[object Object],   },[object Object],},[object Object]
Functional Aspect: Extractors,[object Object],Extractors are objects with an unapply method used to match a value and partition it into constituents – an optional apply is used for synthesis,[object Object],Page 50,[object Object],object EMail {,[object Object],  def apply(prefix: String, domain: String) = prefix + "@" + domain,[object Object],def unapply(s: String): Option[(String,String)] = {,[object Object],   val parts = s split "@",[object Object],   if (parts.length == 2) Some(parts(0), parts(1)) else None,[object Object],  } ,[object Object],},[object Object],object scalafunctions {,[object Object], def main(args:Array[String]) {,[object Object],   val s = "michael.stal@siemens.com",[object Object],   s match { ,[object Object],     case EMail(user, domain) => println(user + " AT " + domain),[object Object],     case _ => println("Invalid e-mail"),[object Object],   },[object Object],  }	,[object Object],},[object Object]
Partial Functions ,[object Object],Partial Functions are not defined for all domain values,[object Object],Can be asked with isDefinedAt whether a domain value is accepted,[object Object],Example: Blocks of Pattern Matching Cases,[object Object],Page 51,[object Object],trait PartialFunction[-D, +T] ,[object Object],extends (D => T) {,[object Object],  def isDefinedAt(x: D): Boolean,[object Object],},[object Object]
Actors,[object Object],Actors have been introduced in the 1970s:,[object Object],the Actor model is a mathematical model of concurrent computationthat treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message received. [Hewitt, 73],[object Object],Page 52,[object Object],Also available in Erlang, Axum, Io, Clojure,[object Object],Provided as library implementation in Scala (demonstrating Scala‘s capability of providing internal DSLs),[object Object]
Actor Classes,[object Object],Class Actor requires to override act() which is the functionality executed by a thread,[object Object],You may also instantiate anonymous actors in a much more convenient way:,[object Object],Page 53,[object Object],import scala.actors.Actor,[object Object],class VolcanextendsActor {,[object Object],def act() {,[object Object],println(“thinking ..."),[object Object],  },[object Object],},[object Object],object SpockRunner {,[object Object],  def main(args:Array[String]) = {,[object Object],valspock = new Volcan,[object Object],spock start,[object Object],  },[object Object],},[object Object],import scala.actors.Actor,[object Object],import Actor._,[object Object],object SpockRunner {,[object Object],  def main(args:Array[String]) = {,[object Object],val spock = actor {,[object Object],	println("thinking ..."),[object Object],    },[object Object],  },[object Object],},[object Object]
Actors that communicate,[object Object],An actor is useless unless it cooperates with other actors,[object Object],Actors communicate via messages,[object Object],In Scala‘s actor library messages are processed in FIFO order,[object Object],Every actor owns an inbound and an outbound mailbox,[object Object],Page 54,[object Object]
Communicating Actors - Example,[object Object],Page 55,[object Object],!,[object Object],Note: react & receive have cousins with timeout arguments:   receiveWithin and reactWithin,[object Object],import scala.actors._,[object Object],import Actor._,[object Object],object Calculator extends Actor {,[object Object],  def fib(n: Int) : Int = { require(n >= 0) // this is a precondition ,[object Object],if (n <= 1) n else fib(n-2) + fib(n-1) },[object Object],  def act() {,[object Object],loop {,[object Object],        react { // or receive if thread must preserve call-stack,[object Object],	       case i:Int => actor {println("Fibonacci of "+i+" is "+fib(i))},[object Object],	       case s:String if (s == „exit")  => {println(„exit!"); exit},[object Object],	       case _ => println("received unknown message") ,[object Object],        },[object Object],     },[object Object],  },[object Object],},[object Object],object ActorDemo extends Application {,[object Object],   Calculator.start // start Actor,[object Object],   for (i <- 0 to 30) Calculator ! i // here we send a msg to the actor,[object Object],Calculator ! "exit",[object Object],},[object Object]

Más contenido relacionado

Was ist angesagt?

DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#Rasan Samarasinghe
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NETRasan Samarasinghe
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in javaGarik Kalashyan
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IAjit Nayak
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scalapramode_ce
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basicsmsemenistyi
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaRasan Samarasinghe
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelRamrao Desai
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language ComparisonRobert Bachmann
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence APIIlio Catallo
 

Was ist angesagt? (20)

DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Javascript
JavascriptJavascript
Javascript
 
Kotlin
KotlinKotlin
Kotlin
 
DITEC - Programming with C#.NET
DITEC - Programming with C#.NETDITEC - Programming with C#.NET
DITEC - Programming with C#.NET
 
Generic Programming in java
Generic Programming in javaGeneric Programming in java
Generic Programming in java
 
Object Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part IObject Oriented Programming using C++ Part I
Object Oriented Programming using C++ Part I
 
Oops presentation
Oops presentationOops presentation
Oops presentation
 
Object-Oriented Programming Using C++
Object-Oriented Programming Using C++Object-Oriented Programming Using C++
Object-Oriented Programming Using C++
 
DIWE - Fundamentals of PHP
DIWE - Fundamentals of PHPDIWE - Fundamentals of PHP
DIWE - Fundamentals of PHP
 
Introduction to Functional Programming with Scala
Introduction to Functional Programming with ScalaIntroduction to Functional Programming with Scala
Introduction to Functional Programming with Scala
 
Scala
ScalaScala
Scala
 
Javascript Basics
Javascript BasicsJavascript Basics
Javascript Basics
 
DISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in JavaDISE - Windows Based Application Development in Java
DISE - Windows Based Application Development in Java
 
Google06
Google06Google06
Google06
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Introduction to C++
Introduction to C++Introduction to C++
Introduction to C++
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
C# / Java Language Comparison
C# / Java Language ComparisonC# / Java Language Comparison
C# / Java Language Comparison
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 

Andere mochten auch

Colegio nacional nicolas esguerra 1
Colegio nacional nicolas esguerra 1Colegio nacional nicolas esguerra 1
Colegio nacional nicolas esguerra 1Santiago Cortes
 
Web page evaluation
Web page evaluationWeb page evaluation
Web page evaluationsarabrownie
 
công ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòn
công ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòncông ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòn
công ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gònlenore810
 
Alonzo Williams Resume.doc 1
Alonzo Williams Resume.doc 1Alonzo Williams Resume.doc 1
Alonzo Williams Resume.doc 1Alonzo Williams
 
Ôm họa vì tăng cường “bản lĩnh đàn ông”
Ôm họa vì tăng cường “bản lĩnh đàn ông”Ôm họa vì tăng cường “bản lĩnh đàn ông”
Ôm họa vì tăng cường “bản lĩnh đàn ông”len398
 
Professional Edition-Datasheet (3)
Professional Edition-Datasheet (3)Professional Edition-Datasheet (3)
Professional Edition-Datasheet (3)davidgbz
 
Los instrumento musicales
Los instrumento musicalesLos instrumento musicales
Los instrumento musicalesJoaquinLopez
 
La MúSica De La India
La MúSica De La IndiaLa MúSica De La India
La MúSica De La IndiaAna Benet
 
Souvenir kantor pajak profile
Souvenir kantor pajak profileSouvenir kantor pajak profile
Souvenir kantor pajak profileCera Production
 

Andere mochten auch (13)

Colegio nacional nicolas esguerra 1
Colegio nacional nicolas esguerra 1Colegio nacional nicolas esguerra 1
Colegio nacional nicolas esguerra 1
 
Notka
NotkaNotka
Notka
 
Lecture 4
Lecture 4Lecture 4
Lecture 4
 
Web page evaluation
Web page evaluationWeb page evaluation
Web page evaluation
 
098765
098765098765
098765
 
công ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòn
công ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòncông ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòn
công ty dịch vụ giúp việc theo giờ giá rẻ nhất ở sài gòn
 
Santiago
SantiagoSantiago
Santiago
 
Alonzo Williams Resume.doc 1
Alonzo Williams Resume.doc 1Alonzo Williams Resume.doc 1
Alonzo Williams Resume.doc 1
 
Ôm họa vì tăng cường “bản lĩnh đàn ông”
Ôm họa vì tăng cường “bản lĩnh đàn ông”Ôm họa vì tăng cường “bản lĩnh đàn ông”
Ôm họa vì tăng cường “bản lĩnh đàn ông”
 
Professional Edition-Datasheet (3)
Professional Edition-Datasheet (3)Professional Edition-Datasheet (3)
Professional Edition-Datasheet (3)
 
Los instrumento musicales
Los instrumento musicalesLos instrumento musicales
Los instrumento musicales
 
La MúSica De La India
La MúSica De La IndiaLa MúSica De La India
La MúSica De La India
 
Souvenir kantor pajak profile
Souvenir kantor pajak profileSouvenir kantor pajak profile
Souvenir kantor pajak profile
 

Ähnlich wie Oop2010 Scala Presentation Stal

A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to ScalaRiccardo Cardin
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: NotesRoberto Casadei
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvmIsaias Barroso
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaDerek Chen-Becker
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with JavaJussi Pohjolainen
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To ScalaPeter Maas
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Languageleague
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?Sarah Mount
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderAndres Almiray
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for KotlinTechMagic
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Arnaud Giuliani
 

Ähnlich wie Oop2010 Scala Presentation Stal (20)

Scala - core features
Scala - core featuresScala - core features
Scala - core features
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to Scala
 
Scala in a nutshell by venkat
Scala in a nutshell by venkatScala in a nutshell by venkat
Scala in a nutshell by venkat
 
Programming in Scala: Notes
Programming in Scala: NotesProgramming in Scala: Notes
Programming in Scala: Notes
 
Scala uma poderosa linguagem para a jvm
Scala   uma poderosa linguagem para a jvmScala   uma poderosa linguagem para a jvm
Scala uma poderosa linguagem para a jvm
 
Scala presentationjune112011
Scala presentationjune112011Scala presentationjune112011
Scala presentationjune112011
 
Stepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to ScalaStepping Up : A Brief Intro to Scala
Stepping Up : A Brief Intro to Scala
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
 
Introduction To Scala
Introduction To ScalaIntroduction To Scala
Introduction To Scala
 
The Scala Programming Language
The Scala Programming LanguageThe Scala Programming Language
The Scala Programming Language
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Reversing JavaScript
Reversing JavaScriptReversing JavaScript
Reversing JavaScript
 
Scala - just good for Java shops?
Scala - just good for Java shops?Scala - just good for Java shops?
Scala - just good for Java shops?
 
Scala ntnu
Scala ntnuScala ntnu
Scala ntnu
 
Svcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilderSvcc Building Rich Applications with Groovy's SwingBuilder
Svcc Building Rich Applications with Groovy's SwingBuilder
 
Scala idioms
Scala idiomsScala idioms
Scala idioms
 
K is for Kotlin
K is for KotlinK is for Kotlin
K is for Kotlin
 
Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017Develop your next app with kotlin @ AndroidMakersFr 2017
Develop your next app with kotlin @ AndroidMakersFr 2017
 
Workshop Scala
Workshop ScalaWorkshop Scala
Workshop Scala
 

Último

25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...Nguyen Thanh Tu Collection
 
Pharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfPharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfSumit Tiwari
 
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in PharmacyASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in PharmacySumit Tiwari
 
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdfArti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdfwill854175
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsDhatriParmar
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxheathfieldcps1
 
Metabolism , Metabolic Fate& disorders of cholesterol.pptx
Metabolism , Metabolic Fate& disorders of cholesterol.pptxMetabolism , Metabolic Fate& disorders of cholesterol.pptx
Metabolism , Metabolic Fate& disorders of cholesterol.pptxDr. Santhosh Kumar. N
 
The First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfThe First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfdogden2
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxiammrhaywood
 
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSDLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSTeacherNicaPrintable
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptxmary850239
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...Nguyen Thanh Tu Collection
 
3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptxmary850239
 
LEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudLEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudDr. Bruce A. Johnson
 
POST ENCEPHALITIS case study Jitendra bhargav
POST ENCEPHALITIS case study  Jitendra bhargavPOST ENCEPHALITIS case study  Jitendra bhargav
POST ENCEPHALITIS case study Jitendra bhargavJitendra Bhargav
 
Alamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxAlamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxDhatriParmar
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptxmary850239
 
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxBBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxProf. Kanchan Kumari
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...Nguyen Thanh Tu Collection
 

Último (20)

25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
25 CHUYÊN ĐỀ ÔN THI TỐT NGHIỆP THPT 2023 – BÀI TẬP PHÁT TRIỂN TỪ ĐỀ MINH HỌA...
 
Pharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdfPharmacology chapter No 7 full notes.pdf
Pharmacology chapter No 7 full notes.pdf
 
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in PharmacyASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
ASTRINGENTS.pdf Pharmacognosy chapter 5 diploma in Pharmacy
 
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdfArti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
Arti Languages Pre Seed Send Ahead Pitchdeck 2024.pdf
 
ANOVA Parametric test: Biostatics and Research Methodology
ANOVA Parametric test: Biostatics and Research MethodologyANOVA Parametric test: Biostatics and Research Methodology
ANOVA Parametric test: Biostatics and Research Methodology
 
Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian Poetics
 
The basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptxThe basics of sentences session 8pptx.pptx
The basics of sentences session 8pptx.pptx
 
Metabolism , Metabolic Fate& disorders of cholesterol.pptx
Metabolism , Metabolic Fate& disorders of cholesterol.pptxMetabolism , Metabolic Fate& disorders of cholesterol.pptx
Metabolism , Metabolic Fate& disorders of cholesterol.pptx
 
The First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdfThe First National K12 TUG March 6 2024.pdf
The First National K12 TUG March 6 2024.pdf
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
 
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYSDLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
DLL Catch Up Friday March 22.docx CATCH UP FRIDAYS
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
 
3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx3.14.24 Gender Discrimination and Gender Inequity.pptx
3.14.24 Gender Discrimination and Gender Inequity.pptx
 
LEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced StudLEAD6001 - Introduction to Advanced Stud
LEAD6001 - Introduction to Advanced Stud
 
POST ENCEPHALITIS case study Jitendra bhargav
POST ENCEPHALITIS case study  Jitendra bhargavPOST ENCEPHALITIS case study  Jitendra bhargav
POST ENCEPHALITIS case study Jitendra bhargav
 
Alamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxAlamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptx
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx
 
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxBBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
 

Oop2010 Scala Presentation Stal

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29. import p.{x => a} the member x of p renamed as a.
  • 30. import p.{x, y} the members x and y of p.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.