Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

2.1 recap from-day_one

735 views

Published on

  • Be the first to comment

2.1 recap from-day_one

  1. 1. Recap of day 1
  2. 2. VariablesScala: Java:val s = “Hello World” public final String s = “Hello World”;var i = 1 public int i = 1;
  3. 3. MethodsScala: Java:def add(x: Int, y: Int): Int = { public int add(int x, int y) { x+y return x + y;} }def add(x: Int, y: Int) = x + ydef doSomething(text: String) { public void doSometing(String text) {} }
  4. 4. Classes and constructorsScala: Java:class Person(val name: String) public class Person { private final String name; public Person(String name) { this.name = name; } public String getName() { return name; } }
  5. 5. TuplesScala: Java:val tuple: Tuple2[Int, String] = Pair<Integer, String> tuple = new Pair<Integer, String>(1, “apple”) (1, “apple”)val quadruple = ... yeah right... ;-) (2, “orange”, 0.5d, false)
  6. 6. The Option typeval someOption: Option[String] = Some("value")val noOption: Option[String] = None
  7. 7. First class funtionsval numbers = List(1, 2, 3, 4, 5)numbers.filter(i => i > 2) // List(3, 4, 5)
  8. 8. Closuresval people = List(Person(“Alf”), Person(“Fredrik”))val name = “Fredrik”people.filter(_.name == name) // Person(“Fredrik”)
  9. 9. Pattern matchingval myObject = ...val res = myObject match { case i: Int if i == 1 => "Found an int which is 1" case s: String => "Found a String" case other => error("Unknown " + other)}
  10. 10. Traitstrait 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 scheduleHigher order functionsImplicit conversionsXML supportTask: The Quiz game

×