Your SlideShare is downloading. ×
0
Recap of day 1
Variables Scala: val s = “Hello World” var i = 1 Java: public final String s = “Hello World”; public int i = 1;
Methods Scala: def add(x: Int, y: Int): Int = { x + y } def add(x: Int, y: Int) = x + y def doSomething(text: String) { } ...
Classes and constructors Scala: class Person(val name: String) Java: public class Person { private final String name; publ...
Tuples Scala: val tuple: Tuple2[Int, String] =  (1, “apple”) val quadruple =  (2, “orange”, 0.5d, false) Java: Pair<Intege...
The Option type val   someOption :  Option [ String ] =  Some ( &quot;value&quot; ) val   noOption :  Option [ String ] = ...
First class funtions val numbers = List(1, 2, 3, 4, 5) numbers.filter(i => i > 2) // List(3, 4, 5)
Closures val people = List(Person(“Alf”), Person(“Fredrik”)) val  name  = “Fredrik” people.filter(_.name ==  name ) // Per...
val  myObject  = ...  val  res  =  myObject   match  { case   i :  Int  if  i  == 1  =>  &quot;Found an int which is 1&quo...
Traits trait Ordered[A] { def compare(that: A): Int def <  (that: A): Boolean = ( this  compare that) <  0 def >  (that: A...
Todays schedule <ul><li>Higher order functions
Upcoming SlideShare
Loading in...5
×

2.1 Recap From Day One

647

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
647
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "2.1 Recap From Day One"

  1. 1. Recap of day 1
  2. 2. Variables Scala: val s = “Hello World” var i = 1 Java: public final String s = “Hello World”; public int i = 1;
  3. 3. Methods Scala: def add(x: Int, y: Int): Int = { x + y } def add(x: Int, y: Int) = x + y def doSomething(text: String) { } Java: public int add(int x, int y) { return x + y; } public void doSometing(String text) { }
  4. 4. Classes and constructors Scala: class Person(val name: String) Java: public class Person { private final String name; public Person(String name) { this.name = name; } public String getName() { return name; } }
  5. 5. Tuples Scala: val tuple: Tuple2[Int, String] = (1, “apple”) val quadruple = (2, “orange”, 0.5d, false) Java: Pair<Integer, String> tuple = new Pair<Integer, String>(1, “apple”) ... yeah right... ;-)
  6. 6. The Option type val someOption : Option [ String ] = Some ( &quot;value&quot; ) val noOption : Option [ String ] = None
  7. 7. First class funtions val numbers = List(1, 2, 3, 4, 5) numbers.filter(i => i > 2) // List(3, 4, 5)
  8. 8. Closures val people = List(Person(“Alf”), Person(“Fredrik”)) val name = “Fredrik” people.filter(_.name == name ) // Person(“ Fredrik”)
  9. 9. val myObject = ... val res = myObject match { case i : Int if i == 1 => &quot;Found an int which is 1&quot; case s : String => &quot;Found a String&quot; case other => error ( &quot;Unknown &quot; + other ) } Pattern matching
  10. 10. Traits trait Ordered[A] { def compare(that: A): Int def < (that: A): Boolean = ( this compare that) < 0 def > (that: A): Boolean = ( this compare that) > 0 def <= (that: A): Boolean = ( this compare that) <= 0 def >= (that: A): Boolean = ( this compare that) >= 0 }
  11. 11. Todays schedule <ul><li>Higher order functions
  12. 12. Implicit conversions
  13. 13. XML support
  14. 14. Task: The Quiz game </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×