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