| 51 |      1 | // Scala Lecture 1
 | 
|  |      2 | //=================
 | 
| 14 |      3 | 
 | 
| 26 |      4 | // Value assignments
 | 
| 123 |      5 | // (their names should be lower case)
 | 
| 199 |      6 | //====================================
 | 
| 21 |      7 | 
 | 
| 202 |      8 | 
 | 
| 14 |      9 | val x = 42
 | 
|  |     10 | val y = 3 + 4
 | 
| 123 |     11 | val z = x / y
 | 
|  |     12 | 
 | 
|  |     13 | // (you cannot reassign values: z = 9 will give an error)
 | 
| 14 |     14 | 
 | 
|  |     15 | 
 | 
| 125 |     16 | // Hello World
 | 
|  |     17 | //=============
 | 
|  |     18 | 
 | 
| 199 |     19 | // an example of a stand-alone Scala file
 | 
|  |     20 | // (in the assignments you must submit a plain Scala script)
 | 
| 125 |     21 | 
 | 
|  |     22 | object Hello extends App { 
 | 
|  |     23 |   println("hello world")
 | 
|  |     24 | }
 | 
|  |     25 | 
 | 
| 199 |     26 | // can then be called with
 | 
| 125 |     27 | //
 | 
|  |     28 | // $> scalac hello-world.scala
 | 
|  |     29 | // $> scala Hello
 | 
|  |     30 | //
 | 
|  |     31 | // $> java -cp /usr/local/src/scala/lib/scala-library.jar:. Hello
 | 
|  |     32 | 
 | 
|  |     33 | 
 | 
|  |     34 | 
 | 
| 25 |     35 | // Collections
 | 
|  |     36 | //=============
 | 
| 14 |     37 | List(1,2,3,1)
 | 
|  |     38 | Set(1,2,3,1)
 | 
|  |     39 | 
 | 
|  |     40 | 1 to 10
 | 
|  |     41 | (1 to 10).toList
 | 
|  |     42 | 
 | 
|  |     43 | (1 until 10).toList
 | 
|  |     44 | 
 | 
| 18 |     45 | // an element in a list
 | 
| 33 |     46 | val lst = List(1, 2, 3, 1)
 | 
|  |     47 | lst(0)
 | 
|  |     48 | lst(2)
 | 
| 18 |     49 | 
 | 
| 34 |     50 | // some alterative syntax for lists
 | 
|  |     51 | 
 | 
| 189 |     52 | 1 :: 2 :: 3 :: Nil
 | 
| 23 |     53 | List(1, 2, 3) ::: List(4, 5, 6)
 | 
| 14 |     54 | 
 | 
| 199 |     55 | // Equality is structural
 | 
|  |     56 | //========================
 | 
|  |     57 | val a = "Dave"
 | 
|  |     58 | val b = "Dave"
 | 
|  |     59 | 
 | 
| 202 |     60 | if (a == b) println("Equal") else println("Unequal")
 | 
| 199 |     61 | 
 | 
|  |     62 | Set(1,2,3) == Set(3,1,2)
 | 
|  |     63 | List(1,2,3) == List(3,1,2)
 | 
|  |     64 | 
 | 
| 202 |     65 | val n1 = 3 + 7
 | 
|  |     66 | val n2 = 5 + 5
 | 
|  |     67 | 
 | 
|  |     68 | n1 == n2
 | 
| 199 |     69 | 
 | 
| 200 |     70 | // this applies to "concrete" values;
 | 
| 199 |     71 | // you cannot compare functions
 | 
|  |     72 | 
 | 
|  |     73 | 
 | 
| 25 |     74 | // Printing/Strings
 | 
|  |     75 | //==================
 | 
| 14 |     76 | 
 | 
|  |     77 | println("test")
 | 
| 15 |     78 | 
 | 
| 33 |     79 | val tst = "This is a " + "test\n" 
 | 
| 14 |     80 | println(tst)
 | 
|  |     81 | 
 | 
|  |     82 | val lst = List(1,2,3,1)
 | 
|  |     83 | 
 | 
| 202 |     84 | 
 | 
| 14 |     85 | println(lst.toString)
 | 
| 202 |     86 | println(lst.mkString(","))
 | 
| 14 |     87 | 
 | 
| 33 |     88 | println(lst.mkString(", "))
 | 
|  |     89 | 
 | 
| 14 |     90 | // some methods take more than one argument
 | 
| 202 |     91 | println(lst.mkString("{", ",", "}"))
 | 
| 14 |     92 | 
 | 
| 32 |     93 | 
 | 
| 200 |     94 | 
 | 
| 25 |     95 | // Conversion methods
 | 
|  |     96 | //====================
 | 
| 14 |     97 | 
 | 
|  |     98 | List(1,2,3,1).toString
 | 
|  |     99 | List(1,2,3,1).toSet
 | 
| 202 |    100 | "hello".toList.tail
 | 
| 14 |    101 | 1.toDouble
 | 
|  |    102 | 
 | 
| 25 |    103 | 
 | 
| 32 |    104 | // useful list methods
 | 
|  |    105 | 
 | 
|  |    106 | List(1,2,3,4).length
 | 
| 25 |    107 | List(1,2,3,4).reverse
 | 
| 32 |    108 | List(1,2,3,4).max
 | 
|  |    109 | List(1,2,3,4).min
 | 
|  |    110 | List(1,2,3,4).sum
 | 
|  |    111 | List(1,2,3,4).take(2).sum
 | 
|  |    112 | List(1,2,3,4).drop(2).sum
 | 
| 199 |    113 | List(1,2,3,4,3).indexOf(3)
 | 
| 32 |    114 | 
 | 
| 36 |    115 | "1,2,3,4,5".split(",").mkString("\n")
 | 
| 202 |    116 | "1,2,3,4,5".split(",").toList
 | 
| 36 |    117 | "1,2,3,4,5".split(",3,").mkString("\n")
 | 
| 25 |    118 | 
 | 
| 200 |    119 | "abcdefg".startsWith("abc")
 | 
|  |    120 | 
 | 
|  |    121 | 
 | 
| 140 |    122 | // Types (slide)
 | 
| 200 |    123 | //===============
 | 
| 25 |    124 | 
 | 
|  |    125 | /* Scala is a strongly typed language
 | 
|  |    126 |  
 | 
| 34 |    127 |  * some base types
 | 
| 14 |    128 | 
 | 
| 25 |    129 |     Int, Long, BigInt, Float, Double
 | 
|  |    130 |     String, Char
 | 
|  |    131 |     Boolean
 | 
|  |    132 | 
 | 
| 34 |    133 |  * some compound types 
 | 
| 12 |    134 | 
 | 
| 25 |    135 |     List[Int],
 | 
|  |    136 |     Set[Double]
 | 
|  |    137 |     Pairs: (Int, String)        
 | 
|  |    138 |     List[(BigInt, String)]
 | 
| 200 |    139 |     Option[Int]
 | 
| 25 |    140 | */
 | 
| 12 |    141 | 
 | 
| 23 |    142 | 
 | 
| 247 |    143 | val name: String = "leo"
 | 
|  |    144 | 
 | 
| 14 |    145 | 
 | 
| 25 |    146 | // Pairs/Tuples
 | 
|  |    147 | //==============
 | 
| 14 |    148 | 
 | 
|  |    149 | val p = (1, "one")
 | 
|  |    150 | p._1
 | 
|  |    151 | p._2
 | 
|  |    152 | 
 | 
|  |    153 | val t = (4,1,2,3)
 | 
|  |    154 | t._4
 | 
|  |    155 | 
 | 
| 25 |    156 | 
 | 
| 200 |    157 | List(("one", 1), ("two", 2), ("three", 3))
 | 
|  |    158 | 
 | 
| 25 |    159 | // Function Definitions
 | 
|  |    160 | //======================
 | 
| 14 |    161 | 
 | 
| 123 |    162 | def incr(x: Int) : Int = x + 1
 | 
|  |    163 | def double(x: Int) : Int = x + x
 | 
|  |    164 | def square(x: Int) : Int = x * x
 | 
| 14 |    165 | 
 | 
| 202 |    166 | def str(x: Int) : String = x.toString
 | 
| 25 |    167 | square(6)
 | 
| 21 |    168 | 
 | 
|  |    169 | 
 | 
| 36 |    170 | // The general scheme for a function: you have to give a type 
 | 
|  |    171 | // to each argument and a return type of the function
 | 
|  |    172 | //
 | 
|  |    173 | //  def fname(arg1: ty1, arg2: ty2,..., argn: tyn): rty = {
 | 
|  |    174 | //    body 
 | 
|  |    175 | //  }
 | 
|  |    176 | 
 | 
|  |    177 | 
 | 
| 200 |    178 | //
 | 
|  |    179 | // BTW: no returns!!
 | 
|  |    180 | // "last" line (expression) in a function determines the result
 | 
|  |    181 | //
 | 
|  |    182 | 
 | 
|  |    183 | def silly(n: Int) : Int = {
 | 
| 202 |    184 |   if (n < 10) n * n
 | 
|  |    185 |   else n + n
 | 
| 200 |    186 | }
 | 
|  |    187 | 
 | 
| 36 |    188 | 
 | 
| 123 |    189 | // If-Conditionals
 | 
|  |    190 | //=================
 | 
| 14 |    191 | 
 | 
| 200 |    192 | // - Scala does not have a then-keyword
 | 
|  |    193 | // - both if-else branches need to be present
 | 
| 189 |    194 | 
 | 
| 143 |    195 | def fact(n: Int) : Int = 
 | 
| 14 |    196 |   if (n == 0) 1 else n * fact(n - 1)
 | 
|  |    197 | 
 | 
| 36 |    198 | 
 | 
|  |    199 | fact(5)
 | 
|  |    200 | fact(150)
 | 
|  |    201 | 
 | 
| 25 |    202 | /* boolean operators
 | 
|  |    203 |  
 | 
|  |    204 |    ==     equals
 | 
|  |    205 |    !      not
 | 
|  |    206 |    && ||  and, or
 | 
|  |    207 | */
 | 
| 15 |    208 | 
 | 
|  |    209 | 
 | 
| 189 |    210 | def fact2(n: BigInt) : BigInt = 
 | 
| 14 |    211 |   if (n == 0) 1 else n * fact2(n - 1)
 | 
|  |    212 | 
 | 
| 25 |    213 | fact2(150)
 | 
|  |    214 | 
 | 
| 26 |    215 | 
 | 
| 189 |    216 | def fib(n: Int) : Int =
 | 
| 14 |    217 |   if (n == 0) 1 else
 | 
| 26 |    218 |     if (n == 1) 1 else fib(n - 1) + fib(n - 2)
 | 
| 14 |    219 | 
 | 
|  |    220 | 
 | 
| 26 |    221 | //gcd - Euclid's algorithm
 | 
|  |    222 | 
 | 
| 202 |    223 | def gcd(a: Int, b: Int) : Int = {
 | 
|  |    224 |   if (b == 0) a 
 | 
|  |    225 |   else {
 | 
|  |    226 |     val foo = 42
 | 
|  |    227 |     gcd(b, a % b)
 | 
|  |    228 |   }  
 | 
|  |    229 | }
 | 
| 26 |    230 | 
 | 
|  |    231 | gcd(48, 18)
 | 
|  |    232 | 
 | 
| 14 |    233 | 
 | 
| 123 |    234 | def power(x: Int, n: Int) : Int =
 | 
| 199 |    235 |   if (n == 0) 1 else x * power(x, n - 1) 
 | 
| 123 |    236 | 
 | 
|  |    237 | power(5, 5)
 | 
|  |    238 | 
 | 
|  |    239 | 
 | 
| 199 |    240 | // Option type
 | 
|  |    241 | //=============
 | 
|  |    242 | 
 | 
|  |    243 | //in Java if something unusually happens, you return null
 | 
|  |    244 | //
 | 
| 200 |    245 | //in Scala you use Options instead
 | 
| 199 |    246 | //   - if the value is present, you use Some(value)
 | 
|  |    247 | //   - if no value is present, you use None
 | 
|  |    248 | 
 | 
|  |    249 | 
 | 
|  |    250 | List(7,2,3,4,5,6).find(_ < 4)
 | 
|  |    251 | List(5,6,7,8,9).find(_ < 4)
 | 
|  |    252 | 
 | 
|  |    253 | 
 | 
|  |    254 | 
 | 
|  |    255 | // error handling with Options (no exceptions)
 | 
|  |    256 | //
 | 
|  |    257 | //  Try(something).getOrElse(what_to_do_in_case_of_an_exception)
 | 
|  |    258 | //
 | 
|  |    259 | import scala.util._
 | 
|  |    260 | import io.Source
 | 
|  |    261 | 
 | 
| 202 |    262 | val my_url = "https://nms.imperial.ac.uk/christian.urban/"
 | 
| 199 |    263 | 
 | 
|  |    264 | Source.fromURL(my_url).mkString
 | 
|  |    265 | 
 | 
|  |    266 | Try(Source.fromURL(my_url).mkString).getOrElse("")
 | 
|  |    267 | 
 | 
|  |    268 | Try(Some(Source.fromURL(my_url).mkString)).getOrElse(None)
 | 
|  |    269 | 
 | 
|  |    270 | 
 | 
|  |    271 | // the same for files
 | 
| 202 |    272 | Try(Some(Source.fromFile("text.txt").mkString)).getOrElse(None)
 | 
| 199 |    273 | 
 | 
| 200 |    274 | // function reading something from files...
 | 
|  |    275 | 
 | 
|  |    276 | def get_contents(name: String) : List[String] = 
 | 
|  |    277 |   Source.fromFile(name).getLines.toList
 | 
|  |    278 | 
 | 
|  |    279 | get_contents("test.txt")
 | 
|  |    280 | 
 | 
|  |    281 | // slightly better - return Nil
 | 
|  |    282 | def get_contents(name: String) : List[String] = 
 | 
| 202 |    283 |   Try(Source.fromFile(name).getLines.toList).getOrElse(List())
 | 
| 200 |    284 | 
 | 
|  |    285 | get_contents("text.txt")
 | 
|  |    286 | 
 | 
|  |    287 | // much better - you record in the type that things can go wrong 
 | 
|  |    288 | def get_contents(name: String) : Option[List[String]] = 
 | 
|  |    289 |   Try(Some(Source.fromFile(name).getLines.toList)).getOrElse(None)
 | 
|  |    290 | 
 | 
|  |    291 | get_contents("text.txt")
 | 
|  |    292 | 
 | 
|  |    293 | 
 | 
| 199 |    294 | 
 | 
| 25 |    295 | // String Interpolations
 | 
|  |    296 | //=======================
 | 
| 14 |    297 | 
 | 
| 26 |    298 | val n = 3
 | 
|  |    299 | println("The square of " + n + " is " + square(n) + ".")
 | 
|  |    300 | 
 | 
|  |    301 | println(s"The square of ${n} is ${square(n)}.")
 | 
|  |    302 | 
 | 
|  |    303 | 
 | 
| 200 |    304 | // helpful for debugging purposes
 | 
|  |    305 | //
 | 
|  |    306 | //         "The most effective debugging tool is still careful thought, 
 | 
|  |    307 | //          coupled with judiciously placed print statements."
 | 
|  |    308 | //                   — Brian W. Kernighan, in Unix for Beginners (1979)
 | 
|  |    309 | 
 | 
| 26 |    310 | 
 | 
| 123 |    311 | def gcd_db(a: Int, b: Int) : Int = {
 | 
| 26 |    312 |   println(s"Function called with ${a} and ${b}.")
 | 
|  |    313 |   if (b == 0) a else gcd_db(b, a % b)
 | 
|  |    314 | }
 | 
|  |    315 | 
 | 
|  |    316 | gcd_db(48, 18)
 | 
|  |    317 | 
 | 
| 14 |    318 | 
 | 
| 124 |    319 | // Asserts/Testing
 | 
| 200 |    320 | //=================
 | 
| 14 |    321 | 
 | 
| 32 |    322 | assert(gcd(48, 18) == 6)
 | 
|  |    323 | 
 | 
|  |    324 | assert(gcd(48, 18) == 5, "The gcd test failed")
 | 
|  |    325 | 
 | 
|  |    326 | 
 | 
| 26 |    327 | // For-Comprehensions (not For-Loops)
 | 
|  |    328 | //====================================
 | 
| 14 |    329 | 
 | 
| 202 |    330 | 
 | 
|  |    331 | for (n <- (1 to 10).toList) yield { 
 | 
|  |    332 |   square(n) + 1
 | 
|  |    333 | }
 | 
| 14 |    334 | 
 | 
| 25 |    335 | for (n <- (1 to 10).toList; 
 | 
|  |    336 |      m <- (1 to 10).toList) yield m * n
 | 
| 21 |    337 | 
 | 
|  |    338 | 
 | 
| 26 |    339 | val mult_table = 
 | 
|  |    340 |   for (n <- (1 to 10).toList; 
 | 
|  |    341 |        m <- (1 to 10).toList) yield m * n
 | 
|  |    342 | 
 | 
| 202 |    343 | println(mult_table.mkString)
 | 
| 26 |    344 | mult_table.sliding(10,10).mkString("\n")
 | 
|  |    345 | 
 | 
| 200 |    346 | // the list/set/... can also be constructed in any 
 | 
|  |    347 | // other way
 | 
| 202 |    348 | for (n <- Set(10,12,4,5,7,8,10)) yield n * n
 | 
| 189 |    349 | 
 | 
| 25 |    350 | 
 | 
| 200 |    351 | // with if-predicates / filters
 | 
| 32 |    352 | 
 | 
|  |    353 | for (n <- (1 to 3).toList; 
 | 
|  |    354 |      m <- (1 to 3).toList;
 | 
| 202 |    355 |      if (n + m) % 2 == 0;
 | 
|  |    356 |      if (n * m) < 2) yield (n, m)
 | 
| 32 |    357 | 
 | 
| 148 |    358 | for (n <- (1 to 3).toList; 
 | 
|  |    359 |      m <- (1 to 3).toList;
 | 
| 202 |    360 |      if ((((n + m) % 2 == 0)))) yield (n, m)
 | 
| 32 |    361 | 
 | 
| 26 |    362 | // with patterns
 | 
|  |    363 | 
 | 
| 199 |    364 | val lst = List((1, 4), (2, 3), (3, 2), (4, 1))
 | 
| 26 |    365 | 
 | 
| 199 |    366 | for ((m, n) <- lst) yield m + n 
 | 
|  |    367 | 
 | 
|  |    368 | for (p <- lst) yield p._1 + p._2 
 | 
| 26 |    369 | 
 | 
| 25 |    370 | 
 | 
| 200 |    371 | // general pattern of for-yield
 | 
| 189 |    372 | 
 | 
| 200 |    373 | for (p <- ...) yield {
 | 
| 189 |    374 |   // potentially complicated
 | 
|  |    375 |   // calculation of a result
 | 
|  |    376 | }
 | 
|  |    377 | 
 | 
| 200 |    378 | // Functions producing multiple outputs
 | 
|  |    379 | //======================================
 | 
| 189 |    380 | 
 | 
| 200 |    381 | def get_ascii(c: Char) : (Char, Int) = (c, c.toInt)
 | 
|  |    382 | 
 | 
|  |    383 | get_ascii('a')
 | 
|  |    384 | 
 | 
|  |    385 | 
 | 
|  |    386 | // .maxBy, sortBy with pairs
 | 
|  |    387 | def get_length(s: String) : (String, Int) = (s, s.length) 
 | 
|  |    388 | 
 | 
|  |    389 | val lst = List("zero", "one", "two", "three", "four", "ten")
 | 
|  |    390 | val strs = for (s <- lst) yield get_length(s)
 | 
|  |    391 | 
 | 
|  |    392 | strs.sortBy(_._2)
 | 
|  |    393 | strs.sortBy(_._1)
 | 
|  |    394 | 
 | 
|  |    395 | strs.maxBy(_._2)
 | 
|  |    396 | strs.maxBy(_._1)
 | 
|  |    397 | 
 | 
|  |    398 | 
 | 
|  |    399 | // For without yield
 | 
|  |    400 | //===================
 | 
| 25 |    401 | 
 | 
| 36 |    402 | // with only a side-effect (no list is produced),
 | 
| 32 |    403 | // has no "yield"
 | 
|  |    404 | 
 | 
|  |    405 | for (n <- (1 to 10)) println(n)
 | 
|  |    406 | 
 | 
|  |    407 | 
 | 
| 199 |    408 | // BTW: a roundabout way of printing out a list, say
 | 
|  |    409 | val lst = ('a' to 'm').toList
 | 
| 140 |    410 | 
 | 
| 202 |    411 | for (n <- lst) println(n)
 | 
|  |    412 | 
 | 
| 199 |    413 | for (i <- (0 until lst.length)) println(lst(i))
 | 
|  |    414 | 
 | 
| 200 |    415 | // Why not just? Why making your life so complicated?
 | 
| 199 |    416 | for (c <- lst) println(c)
 | 
|  |    417 | 
 | 
|  |    418 | // Aside: concurrency 
 | 
|  |    419 | // (ONLY WORKS OUT-OF-THE-BOX IN SCALA 2.11.8, not in SCALA 2.12)
 | 
|  |    420 | // (would need to have this wrapped into a function, or
 | 
|  |    421 | //  REPL called with scala -Yrepl-class-based)
 | 
| 32 |    422 | for (n <- (1 to 10)) println(n)
 | 
|  |    423 | for (n <- (1 to 10).par) println(n)
 | 
|  |    424 | 
 | 
|  |    425 | 
 | 
| 36 |    426 | // for measuring time
 | 
| 140 |    427 | def time_needed[T](n: Int, code: => T) = {
 | 
| 32 |    428 |   val start = System.nanoTime()
 | 
| 140 |    429 |   for (i <- (0 to n)) code
 | 
| 32 |    430 |   val end = System.nanoTime()
 | 
| 140 |    431 |   (end - start) / 1.0e9
 | 
| 32 |    432 | }
 | 
|  |    433 | 
 | 
| 140 |    434 | 
 | 
| 32 |    435 | val list = (1 to 1000000).toList
 | 
|  |    436 | time_needed(10, for (n <- list) yield n + 42)
 | 
|  |    437 | time_needed(10, for (n <- list.par) yield n + 42)
 | 
|  |    438 | 
 | 
|  |    439 | 
 | 
| 140 |    440 | 
 | 
| 200 |    441 | // Just for "Fun": Mutable vs Immutable
 | 
|  |    442 | //=======================================
 | 
|  |    443 | //
 | 
|  |    444 | // - no vars, no ++i, no +=
 | 
|  |    445 | // - no mutable data-structures (no Arrays, no ListBuffers)
 | 
| 137 |    446 | 
 | 
| 32 |    447 | 
 | 
| 200 |    448 | // Q: Count how many elements are in the intersections of two sets?
 | 
|  |    449 | 
 | 
|  |    450 | def count_intersection(A: Set[Int], B: Set[Int]) : Int = {
 | 
|  |    451 |   var count = 0
 | 
|  |    452 |   for (x <- A; if (B contains x)) count += 1 
 | 
|  |    453 |   count
 | 
|  |    454 | }
 | 
| 32 |    455 | 
 | 
| 200 |    456 | val A = (1 to 1000).toSet
 | 
|  |    457 | val B = (1 to 1000 by 4).toSet
 | 
|  |    458 | 
 | 
|  |    459 | count_intersection(A, B)
 | 
|  |    460 | 
 | 
|  |    461 | // but do not try to add .par to the for-loop above
 | 
|  |    462 | 
 | 
| 32 |    463 | 
 | 
| 200 |    464 | //propper parallel version
 | 
|  |    465 | def count_intersection2(A: Set[Int], B: Set[Int]) : Int = 
 | 
|  |    466 |   A.par.count(x => B contains x)
 | 
|  |    467 | 
 | 
|  |    468 | count_intersection2(A, B)
 | 
|  |    469 | 
 | 
| 32 |    470 | 
 | 
| 200 |    471 | //for measuring time
 | 
|  |    472 | def time_needed[T](n: Int, code: => T) = {
 | 
|  |    473 |   val start = System.nanoTime()
 | 
|  |    474 |   for (i <- (0 to n)) code
 | 
|  |    475 |   val end = System.nanoTime()
 | 
|  |    476 |   (end - start) / 1.0e9
 | 
|  |    477 | }
 | 
|  |    478 | 
 | 
|  |    479 | val A = (1 to 1000000).toSet
 | 
|  |    480 | val B = (1 to 1000000 by 4).toSet
 | 
|  |    481 | 
 | 
|  |    482 | time_needed(10, count_intersection(A, B))
 | 
|  |    483 | time_needed(10, count_intersection2(A, B))
 | 
|  |    484 | 
 | 
| 32 |    485 | 
 | 
|  |    486 | // Further Information
 | 
|  |    487 | //=====================
 | 
|  |    488 | 
 | 
| 200 |    489 | // The Scala homepage and general information is at
 | 
| 32 |    490 | //
 | 
|  |    491 | //  http://www.scala-lang.org
 | 
| 123 |    492 | //	http://docs.scala-lang.org
 | 
|  |    493 | //
 | 
|  |    494 | //
 | 
|  |    495 | // It should be fairly easy to install the Scala binary and
 | 
| 200 |    496 | // run Scala on the commandline. People also use Scala with 
 | 
|  |    497 | // Vim and Jedit. I currently settled on VS Code
 | 
| 123 |    498 | //
 | 
| 200 |    499 | //   https://code.visualstudio.com
 | 
| 123 |    500 | //
 | 
| 200 |    501 | // There are also plugins for Eclipse and IntelliJ - YMMV.
 | 
|  |    502 | // Finally there are online editors specifically designed for 
 | 
|  |    503 | // running Scala applications (but do not blame me if you lose 
 | 
|  |    504 | // all what you typed in):
 | 
| 123 |    505 | //
 | 
| 200 |    506 | //   https://scalafiddle.io 
 | 
|  |    507 | //   https://scastie.scala-lang.org
 | 
| 124 |    508 | //
 | 
| 123 |    509 | //
 | 
|  |    510 | //
 | 
|  |    511 | // Scala Library Docs
 | 
| 124 |    512 | //====================
 | 
| 123 |    513 | //
 | 
|  |    514 | //  http://www.scala-lang.org/api/current/
 | 
|  |    515 | //
 | 
|  |    516 | // Scala Tutorials
 | 
|  |    517 | //
 | 
|  |    518 | //  http://docs.scala-lang.org/tutorials/
 | 
|  |    519 | //
 | 
|  |    520 | // There are also a massive number of Scala tutorials on youtube
 | 
| 200 |    521 | // and there are tons of books and free material. Google is your 
 | 
|  |    522 | // friend.
 | 
| 32 |    523 | 
 | 
|  |    524 | 
 | 
| 170 |    525 | 
 | 
|  |    526 | 
 | 
|  |    527 | 
 | 
|  |    528 | 
 | 
|  |    529 | 
 | 
|  |    530 | 
 | 
|  |    531 | 
 | 
| 195 |    532 | 
 | 
|  |    533 | 
 | 
|  |    534 | 
 | 
|  |    535 | 
 | 
|  |    536 | 
 | 
|  |    537 | 
 |