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

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024TopCSSGallery
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024Top 10 Hubspot Development Companies in 2024
Top 10 Hubspot Development Companies in 2024
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 

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