list = new ArrayList<Integer>(); list.add(1); list.add(2); list.add(3); // introduce a counting index, i for (int i = 0; i<list.size(); i++) { Integer element = list.get(i); System.out.println(element); } 3
= new NormalOpener() val oldOpener: Opener = new BrokenOpener() val wine = new Wine() println(newOpener.open(wine)) // contentsOfWine println(oldOpener.open(wine)) // Exception occurs! 7
→ Official language for the bigdata community // joda time based on java import org.joda.time.DateTime, java.util.Date val jodaDt: DateTime = new DateTime(new Date()) val month = month = dt.getMonthOfYear() 8
val MALE = "m"; } // java code public class App { public static void main(String argv[]) { Person$ person = Person$.MODULE$; System.out.println(person.MALE()); } } 9
inputs are declared as inputs - none of them are hidden - and likewise all its outputs are declared as outputs. 1 — Kris Jenkins 1 It is not a concrete definition but easy and intuitive. 11
a side effect if it modifies some state outside its scope or has an observable interaction with its calling functions or the outside world. — Side effect (computer science), Wikipedia 15
// and it is immutable def program(guide: TVGuide, channel: Int, date: Date): Program = { val schedule = guide.getSchedule(channel) schedule.programAt(date) } 17
the startsWith method. // a and b is stateless, and startsWith has no sideEffect. property("startsWith") = forAll { (a: String, b: String) => (a+b).startsWith(a) } 22
programming · Cats: Lightweight, modular, and extensible library for functional programming · Monix: Asynchronous Programming for Scala · Circe: A JSON library for Scala powered by Cats 40