comparison 4-Scala/README.txt @ 70:4198fa4e0df4

Add Scala code and notes
author IBBoard <dev@ibboard.co.uk>
date Sat, 14 Oct 2017 13:39:41 +0100
parents
children
comparison
equal deleted inserted replaced
69:05871e7ac124 70:4198fa4e0df4
1 I've already done Scala development at work, so most of this is just a recap.
2
3 A few things I learned:
4
5 * Never used traits before - mini classes defined with "trait" keyword and included
6 like a "mixin" with the "with" keyword to 'inherit' functionality from multiple parents
7 * Nil is an empty list - probably useful when iterating things and returning a Nil
8 * foldLeft either uses strange syntax ("start /: list {(a, b) … }") or uses currying
9 ("list.foldLeft(start)((a,b) …)")
10 * Strings can be converted to regexes by adding ".r" at the end (I think my work code
11 managed to do without string matching)
12 * Pattern matching with a "match… case" on XML can use squiggly brackets to name a variable
13 (e.g. "case <movie>{movieName}</movie>" matches the tag and puts the contents in movieName)
14 * Scala has a few minor problems:
15 * 2.12 (RPM from the website) won't run files as "scala filename.scala" - it needs to be
16 "scala -nc filename.scala" to disable the compilation daemon
17 * "scala -e <code>" doesn't seem to want to work without "-nc" either
18 * If there are dependencies then it is easier to use sbt. Download from
19 http://www.scala-sbt.org/download.html, create a standard "project/src/scala/package"
20 structure then create build.sbt within "project/" with the contents:
21 name := "Project-Name"
22 version := "1.0"
23 scalaVersion := "2.12.3"
24 Run the project by cd-ing into the project directory and running "sbt run"
25 * Actors have been deprecated and replaced by Akka
26 * sbt compiles code, so you can't have code outside a class or object
27 * Akka actors can only act - they can't easily have other methods as well because
28 creation returns a generic Akka reference to the actor, which doesn't expose the method