Skip to content
Snippets Groups Projects
Commit 06494ede authored by Matt Bovel's avatar Matt Bovel
Browse files

Add documentation

parent a908312f
No related branches found
No related tags found
No related merge requests found
......@@ -53,9 +53,9 @@ You can also directly run it from VSCode using the `run` link:
Inside `src/main/scala`, you can create Scala _worksheets_ (files ending with `.worksheet.sc`). These are special Scala files meant for experimentation where the result of every top-level expression is directly displayed in the IDE. See [the official tutorial about Scala worksheets](https://docs.scala-lang.org/scala3/book/tools-worksheets.html) for more details.
We provide [`sumList.worksheet.sc`](src/main/scala/sumList.worksheet.sc) as an example. If you open it in VSCode, you should see the result of all top-level expressions automatically displayed:
You can try [`01-sumList.worksheet.sc`](src/main/scala/ex01/01-sumList.worksheet.sc) as an example. If you open it in VSCode, you should see the result of all top-level expressions automatically displayed:
![Example of a worksheet opened in VSCode](images/worksheet_screenshot.png)
![Example of a worksheet opened in VSCode](images/worksheet_screenshot.jpg)
Try to change the code and you should see the results automatically updating!
......
images/run_link.jpg

224 KiB | W: | H:

images/run_link.jpg

501 KiB | W: | H:

images/run_link.jpg
images/run_link.jpg
images/run_link.jpg
images/run_link.jpg
  • 2-up
  • Swipe
  • Onion skin
images/worksheet_screenshot.jpg

409 KiB

images/worksheet_screenshot.png

274 KiB

// This is a minimal worksheet example. If you open the folder cs206-demos in
// VSCode and then display this source, you should see all top-level statements
// evaluated in comments, as in:
//
// import scala.annotation.tailrec
//
// val testList = List(1, 2, 3) // List[Int] = List(1, 2, 3)
//
// testList.head // Int = 1
// testList.isEmpty // Boolean = false
// testList.tail // List[Int] = List(2, 3)
// testList.tail.head // Int = 2
// testList ++ List(4, 6) // List[Int] = List(1, 2, 3, 4, 6)
//
// ...
import scala.annotation.tailrec
val testList = List(1, 2, 3)
......
// This demonstrates different ways of writing a sequential `minMax` function in
// Scala. It's meant to be a quick recap of `foldLeft` usage and Scala syntax.
val a = Array(2, 3, 1)
a.min
......@@ -19,7 +22,8 @@ def myMin2(a: Array[Int]) =
def myMin3(a: Array[Int]) =
var min = Int.MaxValue
for v <- a do if v < min then min = v
for v <- a do
if v < min then min = v
min
def myMinMax1(a: Array[Int]) =
......
// This demonstrates how to use parallel collections from a Scala worksheet.
// Note that this works because we added the "scala-parallel-collections"
// dependency in `build.sbt`. Parallel collections are not part of the Scala
// standard library anymore since Scala 2.13.
import scala.collection.parallel.immutable.ParVector
import collection.parallel.CollectionConverters.*
import collection.parallel.{ParSeq, ParSet}
......
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf?forcedownload=1
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_2dyv5wql/0_y9b53u6a
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_icv10qux/0_h4jt9i7k
// Slides: 27
package lecture3
......@@ -7,6 +7,8 @@ package lecture3
import scala.collection.parallel.CollectionConverters.IterableIsParallelizable
import scala.collection.parallel.immutable.ParSet
// Note: we don't use `GenSet` because it is deprecated since Scala 2.13.
def parIntersectionWrong(a: ParSet[Int], b: ParSet[Int]) =
val result = collection.mutable.Set[Int]()
for x <- a do
......
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf?forcedownload=1
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_2dyv5wql/0_y9b53u6a
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_icv10qux/0_h4jt9i7k
// Slides: 28
package lecture3
......@@ -8,6 +8,8 @@ import scala.collection.parallel.CollectionConverters.IterableIsParallelizable
import scala.collection.parallel.immutable.ParSet
import java.util.concurrent.ConcurrentSkipListSet
// Note: we don't use `GenSet` because it is deprecated since Scala 2.13.
def parIntersectionCorrect(a: ParSet[Int], b: ParSet[Int]) =
val result = new ConcurrentSkipListSet[Int]()
for x <- a do
......
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf?forcedownload=1
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_2dyv5wql/0_y9b53u6a
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_icv10qux/0_h4jt9i7k
// Slides: 29
package lecture3
......@@ -8,6 +8,8 @@ import scala.collection.parallel.CollectionConverters.IterableIsParallelizable
import scala.collection.parallel.immutable.ParSet
import java.util.concurrent.ConcurrentSkipListSet
// Note: we don't use `GenSet` because it is deprecated since Scala 2.13.
def intersectionParNoSideEffect(a: ParSet[Int], b: ParSet[Int]) =
if a.size < b.size then a.filter(b(_))
else b.filter(a(_))
......
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_icv10qux/0_h4jt9i7k
// Slides: 31
package lecture3
import scala.collection.*
......
// PDF: https://moodle.epfl.ch/pluginfile.php/3175938/mod_folder/content/0/week03-4-Scala-Parallel-Collections.pdf
// Video: https://mediaspace.epfl.ch/playlist/dedicated/31866/0_icv10qux/0_h4jt9i7k
// Slides: 31
package lecture3
import scala.collection.*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment