SlideShare a Scribd company logo
1 of 89
Scala
the smarter cousin




                     David Rosell
Scala
the smarter cousin
Scala
                  the smarter cousin




Object Oriented
  Functional
Scala
                              the smarter cousin



 general-purpose, type-safe


Object Oriented
  Functional
Scala
                              the smarter cousin



 general-purpose, type-safe


Object Oriented
  Functional
 runs on JVM (and CLR)
OOP
                                  as it should be done

Collections

                Scala are
              library oriented
                                               Duck typing




      Equals                     DSL’s
                                           n!
                                     = 1*2*3*...*n
Closures
scala> var more = 1
more: Int = 1

scala> val addMore = (x: Int) => x + more
addMore: (Int) => Int = <function>
scala> var more = 1
more: Int = 1

scala> val addMore = (x: Int) => x + more
addMore: (Int) => Int = <function>

scala> addMore(1)
res1: Int = 2

scala> more = 10
more: Int = 10

scala> addMore(1)
res3: Int = 11
Using
resources
def writeSomething(file: File): Unit = {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}
def writeSomething(file: File): Unit = {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}
def writeSomething(file: File): Unit = {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}

object WriteToFileSpecs extends Specification {
   ...
}
def writeSomething(file: File): Unit = {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}

“calling writeSomething must write to file” in {
  val file = new File(“test.txt”)
  try {
    writeSomething(file)

      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1)
    } finally {
      file.delete
    }
}
def writeSomething(file: File) {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}

“calling writeSomething must write to file” in {
  val file = new File(“test.txt”)
  try {
    writeSomething(file)

      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1)
    } finally {
      file.delete
    }
}
writer.println(“Hello Kitty”)
      writer.println(new Date)




“calling writeSomething must write to file” in {
  val file = new File(“test.txt”)
  try {
    writeSomething(file)

      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) ??? how to test a ‘now’-date
    } finally {
      file.delete
    }
}
def writeSomething(file: File) {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}
def writeSomething(file: File) {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
  } finally {
    writer.close
  }
}
writer.println(“Hello Kitty”)
      writer.println(new Date)


def writeSomething(file: File) {
  val writer = new PrintWriter(file)
  try {


    } finally {
      writer.close
    }
}
Background




val list = List(“Pelle”, “Stina”)
for (name <- list) {
  println(name)
}
Background




val list = List(“Pelle”, “Stina”)

list.foreach( aFunc(...) )
Background




val list = List(“Pelle”, “Stina”)

list.foreach( aFunc(...) )


def aFunc(s: String): Unit = {
   println(s)
}
Background




         def aFunc(s: String): Unit = {
            println(s)
         }

val list = List(“Pelle”, “Stina”)

list.foreach( (s: String): Unit => { println(s) } )
Background




         def aFunc(s: String): Unit = {
            println(s)
         }

val list = List(“Pelle”, “Stina”)

list.foreach( (s: String) => { println(s) } )
Background




         def aFunc(s: String): Unit = {
            println(s)
         }

val list = List(“Pelle”, “Stina”)

list.foreach( s => println(s) )
Background




         def aFunc(s: String): Unit = {
            println(s)
         }

val list = List(“Pelle”, “Stina”)

list.foreach( _ => println(_) )
Background




         def aFunc(s: String): Unit = {
            println(s)
         }

val list = List(“Pelle”, “Stina”)

list.foreach( println(_) )
Background




val list = List(“Pelle”, “Stina”)

list.foreach( println _ )
Background




val list = List(“Pelle”, “Stina”)
list.foreach( println _ )



for (name <- list) {
  println(name)
}
def writeTo(file: File) {
  val writer = new PrintWriter(file)
  try {
    writer.println(“Hello Kitty”)
    ...
    writer.println(new Date)
  } finally {
    writer.close
  }
}
writer.println(“Hello Kitty”)
      writer.println(new Date)


def writeTo(file: File) {
  val writer = new PrintWriter(file)
  try {
      ...
    } finally {
      writer.close
    }
}
def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}


def writeTo(file: File) {
  val writer = new PrintWriter(file)
  try {
      ...
    } finally {
      writer.close
    }
}
def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}


      def writeTo(file: File) {
        val writer = new PrintWriter(file)
        try {
            ...
          } finally {
            writer.close
          }
      }
def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}


      def writeTo(file: File) {
        val writer = new PrintWriter(file)
        try {
            ...
          } finally {
            writer.close
          }
      }
def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}
def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}


def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      ...
    } finally {
      writer.close
    }
}
def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}


def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}

def op(writer: PrintWriter) {
    writer.println(“Hello Kitty”)
    writer.println(new Date)
}

val file = new File(“test.txt”)

val op = (writer: PrintWriter) => {
            writer.println(“Hello Kitty”)
            writer.println(new Date)
         }

writeTo(file, op)
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

val op = (writer: PrintWriter) => {
            writer.println(“Hello Kitty”)
            writer.println(new Date)
         }

writeTo(file, op)
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

writeTo(file, (writer: PrintWriter) => {
              op)
                 writer.println(“Hello Kitty”)
                 writer.println(new Date)
              }
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

writeTo(file, (writer: PrintWriter) => {
                 writer.println(“Hello Kitty”)
                 writer.println(new Date)
              })
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

               writer => {
                  writer.println(“Hello Kitty”)
                  writer.println(new Date)
               }
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

writeTo(file, writer => {
                 writer.println(“Hello Kitty”)
                 writer.println(new Date)
              })
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}
)(
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}
Currying

                      )(
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
      op(writer)
    } finally {
      writer.close
    }
}
)(
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
    op(writer)

    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

writeTo(file)(writer =>
                 writer.println(“Hello Kitty”)
                 writer.println(new Date))
def writeTo(file: File)(op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
    op(writer)

    } finally {
      writer.close
    }
}


val file = new File(“test.txt”)

writeTo(file) { writer =>
   writer.println(“Hello Kitty”)
   writer.println(new Date)
}
“calling writeTo must write to file” in {
  val file = new File(“test.txt”)
  try {
    writeTo(file)




      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) ??? how to test a ‘now’-date
    } finally {
      file.delete
    }
}
writeTo(file) { writer =>
         writer.println(“Hello Kitty”)
         writer.println(new Date)
      }


“calling writeTo must write to file” in {
  val file = new File(“test.txt”)
  try {
    writeTo(file)




      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) ??? how to test a ‘now’-date
    } finally {
      file.delete
    }
}
“calling writeTo must write to file” in {
  val file = new File(“test.txt”)
  try {
    writeTo(file) { writer =>
        writer.println(“Hello Kitty”)
        writer.println(new Date)
    }

      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) ??? how to test a ‘now’-date
    } finally {
      file.delete
    }
}
“calling writeTo must write to file” in {
  val file = new File(“test.txt”)
  try {
    val now = new Date
    writeTo(file) { writer =>
        writer.println(“Hello Kitty”)
        writer.println(new Date)
    }
    val cont = Source.fromFile(file).getLines.toList
    cont(0) must be equalTo “Hello Kitty”
    cont(1) ??? how to test a ‘now’-date
  } finally {
    file.delete
  }
}
“calling writeTo must write to file” in {
  val file = new File(“test.txt”)
  try {
    val now = new Date
    writeTo(file) { writer =>
        writer.println(“Hello Kitty”)
        writer.println(now)
    }
    val cont = Source.fromFile(file).getLines.toList
    cont(0) must be equalTo “Hello Kitty”
    cont(1) must be equalTo now.toString
  } finally {
    file.delete
  }
}
def writeTo(file: File, op: PrintWriter => Unit) {
  val writer = new PrintWriter(file)
  try {
    op(writer)
  } finally {
    writer.close
  }
}

“calling writeTo must write to file” in {
  val file = new File(“test.txt”)
  try {
    val now = new Date
    writeTo(file) { writer =>
        writer.println(“Hello Kitty”)
        writer.println(now)
    }
    val cont = Source.fromFile(file).getLines.toList
    cont(0) must be equalTo “Hello Kitty”
    cont(1) must be equalTo now.toString
  } finally {
    file.delete
  }
}
“calling writeSomething must write to file” in {
    val file = new File(“test.txt”)
    try {
      val now = new Date
      writeTo(file) { writer =>
          writer.println(“Hello Kitty”)
          writer.println(now)
      }
      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) must be equalTo now.toString
    } finally {
      file.delete
    }
}
“calling writeSomething must write to file” in {
   withFile { file =>
      val now = new Date
      writeTo(file) { writer =>
         writer.println(“Hello Kitty”)
         writer.println(now)
      }
      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) must be equalTo now.toString
   }
}


def withFile(op: File => Unit) {
  val file = new File(“test.txt”)
  try {
    op(file)
    } finally {
      file.delete
    }
}
“calling writeSomething must write to file” in {
   withFile { file =>
      val now = new Date
      writeTo(file) { writer =>
         writer.println(“Hello Kitty”)
         writer.println(now)
      }
      val cont = Source.fromFile(file).getLines.toList
      cont(0) must be equalTo “Hello Kitty”
      cont(1) must be equalTo now.toString
   }
}
“calling writeSomething must write to file” in {
   withFile { file =>
      val now = new Date
      writeTo(file) { writer =>
         writer.println(“Hello Kitty”)
         writer.println(now)
      }
      val cont = Source.fromFile(file).getLines.toList
      validate(file) { cont =>
      cont(0) must be equalTo “Hello Kitty”
      cont(1) must be equalTo now.toString

    }
}
“calling writeSomething must write to file” in {
   withFile { file =>
      val now = new Date
      writeTo(file) { writer =>
         writer.println(“Hello Kitty”)
         writer.println(now)
      }
      validate(file) { cont =>
         cont(0) must be equalTo “Hello Kitty”
         cont(1) must be equalTo now.toString
      }
   }
}


def validate(file: File)(op: List[String] => Unit) {
   val cont = Source.fromFile(file).getLines.toList
   op(cont)
}
def withFile(op: File => Unit) {
  val file = new File(“test.txt”)
  try {
    op(file)
    } finally {
      file.delete
    }
}


def validate(file: File)(op: List[String] => Unit) {
   val cont = Source.fromFile(file).getLines.toList
   op(cont)
}
def withFile(op: File => Unit) {
  val file = new File(“test.txt”)
  try {
    op(file)
    } finally {
      file.delete
    }
}


def validate(file: File)(op: List[String] => Unit) {
   val cont = Source.fromFile(file).getLines.toList
   op(cont)
}
object WriteToFileSpecs extends Specification with TestFileHelper {
   ...
}


trait TestFileHelper {
    def withFile(op: File => Unit) {
       val file = new File(“test.txt”)
       try {
          op(file)
       } finally {
          file.delete
       }
    }
    def validate(file: File)(op: List[String] => Unit) {
       val cont = Source.fromFile(file).getLines.toList
       op(cont)
    }
}
JVM      Community

      Language
JVM   Community
Scala gives

• More concise - type inference
• More expressive - operator notation
• OOP for real
• Slick functional collection api
• Full access to Java
1’st edition free
http://www.artima.com/
pins1ed/
David Rosell
David Rosell

BlogSpot: http://drsimplestuff.blogspot.com
 GitHub: https://github.com/daros
   E-mail: david.rosell@redpill-linpro.com

More Related Content

What's hot

The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189Mahmoud Samir Fayed
 
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."sjabs
 
The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210Mahmoud Samir Fayed
 
The Ring programming language version 1.5.2 book - Part 39 of 181
The Ring programming language version 1.5.2 book - Part 39 of 181The Ring programming language version 1.5.2 book - Part 39 of 181
The Ring programming language version 1.5.2 book - Part 39 of 181Mahmoud Samir Fayed
 
GeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with GroovyGeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with GroovyIván López Martín
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemSages
 
Event Sourcing and Functional Programming
Event Sourcing and Functional ProgrammingEvent Sourcing and Functional Programming
Event Sourcing and Functional ProgrammingGlobalLogic Ukraine
 
The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189Mahmoud Samir Fayed
 
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202Mahmoud Samir Fayed
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Jung Kim
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101Ankur Gupta
 
SPL: The Undiscovered Library - DataStructures
SPL: The Undiscovered Library -  DataStructuresSPL: The Undiscovered Library -  DataStructures
SPL: The Undiscovered Library - DataStructuresMark Baker
 
GR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 

What's hot (19)

The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189The Ring programming language version 1.6 book - Part 15 of 189
The Ring programming language version 1.6 book - Part 15 of 189
 
Kitura Todolist tutorial
Kitura Todolist tutorialKitura Todolist tutorial
Kitura Todolist tutorial
 
Meetup slides
Meetup slidesMeetup slides
Meetup slides
 
はじめてのGroovy
はじめてのGroovyはじめてのGroovy
はじめてのGroovy
 
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
 
The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210The Ring programming language version 1.9 book - Part 48 of 210
The Ring programming language version 1.9 book - Part 48 of 210
 
The Ring programming language version 1.5.2 book - Part 39 of 181
The Ring programming language version 1.5.2 book - Part 39 of 181The Ring programming language version 1.5.2 book - Part 39 of 181
The Ring programming language version 1.5.2 book - Part 39 of 181
 
GeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with GroovyGeeCON Prague 2014 - Metaprogramming with Groovy
GeeCON Prague 2014 - Metaprogramming with Groovy
 
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data EcosystemWprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
Wprowadzenie do technologii Big Data / Intro to Big Data Ecosystem
 
Event Sourcing and Functional Programming
Event Sourcing and Functional ProgrammingEvent Sourcing and Functional Programming
Event Sourcing and Functional Programming
 
The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189
 
Realm to Json & Royal
Realm to Json & RoyalRealm to Json & Royal
Realm to Json & Royal
 
The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202The Ring programming language version 1.8 book - Part 30 of 202
The Ring programming language version 1.8 book - Part 30 of 202
 
Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법Swift와 Objective-C를 함께 쓰는 방법
Swift와 Objective-C를 함께 쓰는 방법
 
Python Performance 101
Python Performance 101Python Performance 101
Python Performance 101
 
SPL: The Undiscovered Library - DataStructures
SPL: The Undiscovered Library -  DataStructuresSPL: The Undiscovered Library -  DataStructures
SPL: The Undiscovered Library - DataStructures
 
GR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective GroovyGR8Conf 2011: Effective Groovy
GR8Conf 2011: Effective Groovy
 
Intro to The PHP SPL
Intro to The PHP SPLIntro to The PHP SPL
Intro to The PHP SPL
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 

Viewers also liked

Git out of dependency hell
Git out of dependency hellGit out of dependency hell
Git out of dependency hellRedpill Linpro
 
Musical instruments
Musical instrumentsMusical instruments
Musical instrumentsNoe A
 
Sixth question evaluation
Sixth question evaluationSixth question evaluation
Sixth question evaluationnicolemason
 
Fifth question evaluation
Fifth question evaluationFifth question evaluation
Fifth question evaluationnicolemason
 
Forth question evaluvation
Forth question evaluvationForth question evaluvation
Forth question evaluvationnicolemason
 

Viewers also liked (7)

Git out of dependency hell
Git out of dependency hellGit out of dependency hell
Git out of dependency hell
 
Musical instruments
Musical instrumentsMusical instruments
Musical instruments
 
Sixth question evaluation
Sixth question evaluationSixth question evaluation
Sixth question evaluation
 
Mrs. Conway's Favorites
Mrs. Conway's FavoritesMrs. Conway's Favorites
Mrs. Conway's Favorites
 
Fifth question evaluation
Fifth question evaluationFifth question evaluation
Fifth question evaluation
 
Forth question evaluvation
Forth question evaluvationForth question evaluvation
Forth question evaluvation
 
DLA - The European Initiative
DLA  - The European InitiativeDLA  - The European Initiative
DLA - The European Initiative
 

Similar to Scala - den smarta kusinen

Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Baruch Sadogursky
 
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
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismEelco Visser
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?Tomasz Wrobel
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlinintelliyole
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kirill Rozov
 
Scala jeff
Scala jeffScala jeff
Scala jeffjeff kit
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsFranco Lombardo
 
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 3Kirill Rozov
 
What's New in Swift 4
What's New in Swift 4What's New in Swift 4
What's New in Swift 4Young Hoo Kim
 
Python built in functions
Python built in functionsPython built in functions
Python built in functionsRakshitha S
 

Similar to Scala - den smarta kusinen (20)

Assignment6
Assignment6Assignment6
Assignment6
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
1 the ruby way
1   the ruby way1   the ruby way
1 the ruby way
 
Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014Groovy puzzlers по русски с Joker 2014
Groovy puzzlers по русски с Joker 2014
 
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...
 
Ti1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: PolymorphismTi1220 Lecture 7: Polymorphism
Ti1220 Lecture 7: Polymorphism
 
(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?(How) can we benefit from adopting scala?
(How) can we benefit from adopting scala?
 
Idiomatic Kotlin
Idiomatic KotlinIdiomatic Kotlin
Idiomatic Kotlin
 
Introduction to Go for Java Programmers
Introduction to Go for Java ProgrammersIntroduction to Go for Java Programmers
Introduction to Go for Java Programmers
 
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
 
Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2Kotlin Basics - Apalon Kotlin Sprint Part 2
Kotlin Basics - Apalon Kotlin Sprint Part 2
 
Scala jeff
Scala jeffScala jeff
Scala jeff
 
Kotlin, why?
Kotlin, why?Kotlin, why?
Kotlin, why?
 
Kotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functionsKotlin from-scratch 2 - functions
Kotlin from-scratch 2 - functions
 
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
 
What's New in Swift 4
What's New in Swift 4What's New in Swift 4
What's New in Swift 4
 
Python built in functions
Python built in functionsPython built in functions
Python built in functions
 

Recently uploaded

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 

Recently uploaded (20)

Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 

Scala - den smarta kusinen

  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. Scala the smarter cousin David Rosell
  • 16. Scala the smarter cousin Object Oriented Functional
  • 17. Scala the smarter cousin general-purpose, type-safe Object Oriented Functional
  • 18. Scala the smarter cousin general-purpose, type-safe Object Oriented Functional runs on JVM (and CLR)
  • 19.
  • 20. OOP as it should be done Collections Scala are library oriented Duck typing Equals DSL’s n! = 1*2*3*...*n
  • 22.
  • 23. scala> var more = 1 more: Int = 1 scala> val addMore = (x: Int) => x + more addMore: (Int) => Int = <function>
  • 24. scala> var more = 1 more: Int = 1 scala> val addMore = (x: Int) => x + more addMore: (Int) => Int = <function> scala> addMore(1) res1: Int = 2 scala> more = 10 more: Int = 10 scala> addMore(1) res3: Int = 11
  • 25.
  • 27. def writeSomething(file: File): Unit = { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } }
  • 28. def writeSomething(file: File): Unit = { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } }
  • 29. def writeSomething(file: File): Unit = { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } } object WriteToFileSpecs extends Specification { ... }
  • 30. def writeSomething(file: File): Unit = { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } } “calling writeSomething must write to file” in { val file = new File(“test.txt”) try { writeSomething(file) val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) } finally { file.delete } }
  • 31. def writeSomething(file: File) { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } } “calling writeSomething must write to file” in { val file = new File(“test.txt”) try { writeSomething(file) val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) } finally { file.delete } }
  • 32. writer.println(“Hello Kitty”) writer.println(new Date) “calling writeSomething must write to file” in { val file = new File(“test.txt”) try { writeSomething(file) val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) ??? how to test a ‘now’-date } finally { file.delete } }
  • 33. def writeSomething(file: File) { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } }
  • 34. def writeSomething(file: File) { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) writer.println(new Date) } finally { writer.close } }
  • 35. writer.println(“Hello Kitty”) writer.println(new Date) def writeSomething(file: File) { val writer = new PrintWriter(file) try { } finally { writer.close } }
  • 36. Background val list = List(“Pelle”, “Stina”) for (name <- list) { println(name) }
  • 37. Background val list = List(“Pelle”, “Stina”) list.foreach( aFunc(...) )
  • 38. Background val list = List(“Pelle”, “Stina”) list.foreach( aFunc(...) ) def aFunc(s: String): Unit = { println(s) }
  • 39. Background def aFunc(s: String): Unit = { println(s) } val list = List(“Pelle”, “Stina”) list.foreach( (s: String): Unit => { println(s) } )
  • 40. Background def aFunc(s: String): Unit = { println(s) } val list = List(“Pelle”, “Stina”) list.foreach( (s: String) => { println(s) } )
  • 41. Background def aFunc(s: String): Unit = { println(s) } val list = List(“Pelle”, “Stina”) list.foreach( s => println(s) )
  • 42. Background def aFunc(s: String): Unit = { println(s) } val list = List(“Pelle”, “Stina”) list.foreach( _ => println(_) )
  • 43. Background def aFunc(s: String): Unit = { println(s) } val list = List(“Pelle”, “Stina”) list.foreach( println(_) )
  • 44. Background val list = List(“Pelle”, “Stina”) list.foreach( println _ )
  • 45. Background val list = List(“Pelle”, “Stina”) list.foreach( println _ ) for (name <- list) { println(name) }
  • 46. def writeTo(file: File) { val writer = new PrintWriter(file) try { writer.println(“Hello Kitty”) ... writer.println(new Date) } finally { writer.close } }
  • 47. writer.println(“Hello Kitty”) writer.println(new Date) def writeTo(file: File) { val writer = new PrintWriter(file) try { ... } finally { writer.close } }
  • 48. def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) } def writeTo(file: File) { val writer = new PrintWriter(file) try { ... } finally { writer.close } }
  • 49. def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) } def writeTo(file: File) { val writer = new PrintWriter(file) try { ... } finally { writer.close } }
  • 50. def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) } def writeTo(file: File) { val writer = new PrintWriter(file) try { ... } finally { writer.close } }
  • 51. def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) }
  • 52. def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) } def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { ... } finally { writer.close } }
  • 53. def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) } def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } }
  • 54. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } def op(writer: PrintWriter) { writer.println(“Hello Kitty”) writer.println(new Date) } val file = new File(“test.txt”) val op = (writer: PrintWriter) => { writer.println(“Hello Kitty”) writer.println(new Date) } writeTo(file, op)
  • 55. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) val op = (writer: PrintWriter) => { writer.println(“Hello Kitty”) writer.println(new Date) } writeTo(file, op)
  • 56. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) writeTo(file, (writer: PrintWriter) => { op) writer.println(“Hello Kitty”) writer.println(new Date) }
  • 57. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) writeTo(file, (writer: PrintWriter) => { writer.println(“Hello Kitty”) writer.println(new Date) })
  • 58. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) writer => { writer.println(“Hello Kitty”) writer.println(new Date) }
  • 59. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) writeTo(file, writer => { writer.println(“Hello Kitty”) writer.println(new Date) })
  • 60. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } }
  • 61. )( def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } }
  • 62. Currying )( def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } }
  • 63. )( def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) writeTo(file)(writer => writer.println(“Hello Kitty”) writer.println(new Date))
  • 64. def writeTo(file: File)(op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } val file = new File(“test.txt”) writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(new Date) }
  • 65. “calling writeTo must write to file” in { val file = new File(“test.txt”) try { writeTo(file) val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) ??? how to test a ‘now’-date } finally { file.delete } }
  • 66. writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(new Date) } “calling writeTo must write to file” in { val file = new File(“test.txt”) try { writeTo(file) val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) ??? how to test a ‘now’-date } finally { file.delete } }
  • 67. “calling writeTo must write to file” in { val file = new File(“test.txt”) try { writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(new Date) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) ??? how to test a ‘now’-date } finally { file.delete } }
  • 68. “calling writeTo must write to file” in { val file = new File(“test.txt”) try { val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(new Date) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) ??? how to test a ‘now’-date } finally { file.delete } }
  • 69. “calling writeTo must write to file” in { val file = new File(“test.txt”) try { val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } finally { file.delete } }
  • 70. def writeTo(file: File, op: PrintWriter => Unit) { val writer = new PrintWriter(file) try { op(writer) } finally { writer.close } } “calling writeTo must write to file” in { val file = new File(“test.txt”) try { val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } finally { file.delete } }
  • 71. “calling writeSomething must write to file” in { val file = new File(“test.txt”) try { val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } finally { file.delete } }
  • 72. “calling writeSomething must write to file” in { withFile { file => val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } } def withFile(op: File => Unit) { val file = new File(“test.txt”) try { op(file) } finally { file.delete } }
  • 73. “calling writeSomething must write to file” in { withFile { file => val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } val cont = Source.fromFile(file).getLines.toList cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } }
  • 74. “calling writeSomething must write to file” in { withFile { file => val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } val cont = Source.fromFile(file).getLines.toList validate(file) { cont => cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } }
  • 75. “calling writeSomething must write to file” in { withFile { file => val now = new Date writeTo(file) { writer => writer.println(“Hello Kitty”) writer.println(now) } validate(file) { cont => cont(0) must be equalTo “Hello Kitty” cont(1) must be equalTo now.toString } } } def validate(file: File)(op: List[String] => Unit) { val cont = Source.fromFile(file).getLines.toList op(cont) }
  • 76. def withFile(op: File => Unit) { val file = new File(“test.txt”) try { op(file) } finally { file.delete } } def validate(file: File)(op: List[String] => Unit) { val cont = Source.fromFile(file).getLines.toList op(cont) }
  • 77. def withFile(op: File => Unit) { val file = new File(“test.txt”) try { op(file) } finally { file.delete } } def validate(file: File)(op: List[String] => Unit) { val cont = Source.fromFile(file).getLines.toList op(cont) }
  • 78. object WriteToFileSpecs extends Specification with TestFileHelper { ... } trait TestFileHelper { def withFile(op: File => Unit) { val file = new File(“test.txt”) try { op(file) } finally { file.delete } } def validate(file: File)(op: List[String] => Unit) { val cont = Source.fromFile(file).getLines.toList op(cont) } }
  • 79.
  • 80.
  • 81.
  • 82.
  • 83. JVM Community Language
  • 84. JVM Community
  • 85. Scala gives • More concise - type inference • More expressive - operator notation • OOP for real • Slick functional collection api • Full access to Java
  • 86.
  • 89. David Rosell BlogSpot: http://drsimplestuff.blogspot.com GitHub: https://github.com/daros E-mail: david.rosell@redpill-linpro.com

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. general-purpose, \ntype-safe language \n for the Java Platform \nthat combines \n object-oriented \n and \n functional programming\n
  23. general-purpose, \ntype-safe language \n for the Java Platform \nthat combines \n object-oriented \n and \n functional programming\n
  24. general-purpose, \ntype-safe language \n for the Java Platform \nthat combines \n object-oriented \n and \n functional programming\n
  25. general-purpose, \ntype-safe language \n for the Java Platform \nthat combines \n object-oriented \n and \n functional programming\n
  26. general-purpose, \ntype-safe language \n for the Java Platform \nthat combines \n object-oriented \n and \n functional programming\n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n