- Notifications
You must be signed in to change notification settings - Fork19
Lunatech course - "Moving forward from Scala 2 to Scala 3"
License
lunatech-labs/lunatech-scala2-to-scala3-course
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The target audience for this course is the ScalaApplication Developer Community. In other words, the focus is on people who use the language to develop 'end-user' applications and not necessarily those developers who design and write libraries, toolkits or frameworks (although they may benefit from what is in this course if they haven't already worked with Scala 3).
The goal of the course is to explore the new features in the Scala language brought bythe Scala 3 project.
We start from an existing Scala 2 application: an [Akka] actor based Sudoku solver. We start from the application as-is, but with an sbt build definition that uses the Scala 3 compiler.
Through a series of exercises, we look at specific Scala 3 features and apply these to the Scala 2 code, thereby transforming it step-by-step into a version that exploits a whole series of nice features offered by the new language.
Note that this course gets updated on regular basis, so keep watching this space!
Some prerequisites need to be met in order to install the course. The following componentsneed to be installed:
- Coursier
- A Java JDK (JDK 11 or 17). Note that Coursier allows you to install a JDK
- The
cmtcCourse Management Tools Client CLI - An IDE
The following sections detail how to install these components.
The course can be installed usingCoursier.
Coursier will, as part of its base installation, install a number of useful applications among which:
sbt- the Scala Build Toolscala-cli- the Scala interactive toolkitscala- the Scala REPLscalac- the Scala compilerjava- JDK 8 by default (we will need to install a more recent version of the JDK)
Coursier, once installed, will make it extremely easy to switch between different versions of theinstalled tools (such as the Scala compiler and REPL).
If you haven't installed Coursier, install it first by following theInstall Scala on your computer instructions.
If you haven't installed a JDK yet (version 11 or 17), you can do this in the following manner.In a terminal on your system, issue the following command to install JDK 11:
$ cs java --jvm temurin:1.11 --setupCheckingif~/.profile,~/.zprofile,~/.bash_profile need(s) updating.Some shell configuration files were updated. It is recommended to close this terminal once the setupcommand is done, and open a new onefor the changes to be taken into account
Close the current terminal and start a new one. Verify that the JDK is installed correctly:
$ java -versionopenjdk version"11.0.20" 2023-07-18OpenJDK Runtime Environment Temurin-11.0.20+8 (build 11.0.20+8)OpenJDK 64-Bit Server VM Temurin-11.0.20+8 (build 11.0.20+8, mixed mode)During the course, you will use thecmtc command, theCourseManagementToolsClient CLI.
Install it using Coursier from the command line (all Linux, Mac, or Windows platforms) as follows:
$ cs install --contrib cmtcWrote cmtcVerify that the installation was successful by running thecmtc command. You should see the following output:
$ cmtcUsage: cmtc<COMMAND>Commands: goto-exercise Move to a given exercise. Pullin tests and readme filesfor that exercise goto-first-exercise Move to the first exercise. Pullin tests and readme filesfor that exercise install Install a course - from either alocal directory, a zip file on thelocal file system or a Github project list-exercises List all exercises and their IDsin the repo. Mark the active exercise with a star list-saved-states List all saved exercise states,if any. next-exercise Move to the next exercise. Pullin tests and readme filesfor that exercise previous-exercise Move to the previous exercise. Pullin tests and readme filesfor that exercise pull-solution Pullin all codefor the active exercise. Alllocal changes are discarded pull-template Selectively pullin a given file or folderfor the active exercise restore-state Restore a previously saved exercise state save-state Save the state of the active exercise set-current-course Sets the current course to point to a directory version Print version info
Installing this course can be done via thecmtc install command as follows:
$ cmtc install -s scalacenter/scala3-migration-courseDownloading studentified course from'https://github.com/scalacenter/scala3-migration-course/releases/download/v0.1.0/scala3-migration-course-student.zip' to courses directoryProject scala3-migration-course (v0.1.0) successfully installed to: /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-courseCurrent courseset to'/Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course'Exercisesin repository: 1.* exercise_000_initial_state 2. exercise_001_install_sbt_scala3_migrate 3. exercise_002_migrate_dependencies 4. exercise_003_migrate_scalac_options 5. exercise_004_migrate_syntax 6. exercise_005_migrate_types 7. exercise_006_update_scala_version
Verify that the course was installed correctly by launchingsbt test in the root folder of thecourse exercises. You should see the following output:
$ sbttest[info] welcome to sbt 1.9.3 (Eclipse Adoptium Java 11.0.20)[info] loading settingsfor project global-plugins from idea.sbt ...[info] loading global plugins from /Users/ericloots/.sbt/1.0/plugins[info] loading settingsfor project scala3-migration-course-build from plugins.sbt ...[info] loading project definition from /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course/project[info] loading settingsfor project main from build.sbt ...[info]set current project to main (in build file:/Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course/)[info] compiling 8 Scala sources to /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course/target/scala-2.13/classes ...[warn] 1 deprecation[warn] 1 deprecation (since 2.13.11)[warn] 2 deprecationsin total; re-run with -deprecationfor details[warn] three warnings found[info] compiling 8 Scala sources to /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/scala3-migration-course/target/scala-2.13/test-classes ...[warn] 1 deprecation[warn] 1 deprecation (since 2.13.3)[warn] 2 deprecationsin total; re-run with -deprecationfor details[warn] three warnings found[info] example.SyntaxRewritesTests:[info] + parentheses around lambda parameter 0.017s[info] + auto-application 0.0s[info] example.FunctorTests:[info] + either left functor 0.002s[info] example.DiffUtilTests:[info] + diff 0.01s[info] example.CatsTests:[info] + combine all strings 0.203s[info] example.TypeIncompatTests:[info] +type incompat 0.0s[info] example.BetterMonadicForTests:[info] + count twice 0.001s[info] example.ScalametaTests:[info] + parse Scala expression 0.076s|D| example.BuildInfo.scalacOptions = List(-encoding, UTF-8, -target:jvm-1.8, -Xsource:3, -Wunused:imports,privates,locals, -explaintypes)[info] example.BuildInfoTests:[info] + scalacOptions 0.003s[info] Passed: Total 9, Failed 0, Errors 0, Passed 9[success] Total time: 4 s, completed 5 Sep 2023, 16:15:22
Installing this course can be done via thecmtc install command as follows:
$ cmtc install -f -s lunatech-labs/lunatech-scala2-to-scala3-courseDownloading studentified course from'https://github.com/lunatech-labs/lunatech-scala2-to-scala3-course/releases/download/3.0.2/lunatech-scala2-to-scala3-course-student.zip' to courses directoryProject lunatech-scala2-to-scala3-course (3.0.2) successfully installed to: /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-courseCurrent courseset to'/Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course'Exercisesin repository: 1.* exercise_000_sudoku_solver_initial_state 2. exercise_001_dotty_deprecated_syntax_rewriting 3. exercise_002_dotty_new_syntax_and_indentation_based_syntax 4. exercise_003_top_level_definitions 5. exercise_004_parameter_untupling 6. exercise_005_extension_methods 7. exercise_006_using_and_summon 8. exercise_007_givens 9. exercise_008_enum_and_export 10. exercise_009_union_types 11. exercise_010_opaque_type_aliases 12. exercise_011_multiversal_equality 13. exercise_020_opaque_type_aliases_alt 14. exercise_021_multiversal_equality
As can be seen in the above output,cmtc installed the course in the/Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course folder. Note that this location is OS specific, so, take a note of the location.
Verify that the course was installed correctly by launchingsbt test in the root folder of thecourse exercises. You should see the following output:
$ sbttest[info] welcome to sbt 1.9.3 (Eclipse Adoptium Java 11.0.20)[info] loading settingsfor project global-plugins from idea.sbt ...[info] loading global plugins from /Users/ericloots/.sbt/1.0/plugins[info] loading settingsfor project lunatech-scala2-to-scala3-course-build from plugins.sbt ...[info] loading project definition from /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course/project[info] compiling 1 Scalasource to /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course/project/target/scala-2.12/sbt-1.0/classes ...[info] loading settingsfor project moving-from-scala-2-to-scala-3 from build.sbt ...[info]set current project to moving-from-scala-2-to-scala-3 (in build file:/Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course/)[info] compiling 11 Scala sources to /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course/target/scala-2.13/classes ...[warn] /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course/src/main/scala/org/lunatechlabs/dotty/sudoku/SudokuProblemSender.scala:81:44: Auto-application to`()` is deprecated. Supply the empty argument list`()` explicitly to invoke method next,[warn] or remove the empty argument list from its definition (Java-defined methods are exempt).[warn] In Scala 3, an unapplied method like this will be eta-expanded into a function.[warn] val nextRowUpdates = rowUpdatesSeq.next[warn] ^[warn] one warning found[info] compiling 4 Scala sources to /Users/ericloots/Library/Caches/com.lunatech.cmt/Courses/lunatech-scala2-to-scala3-course/target/scala-2.13/test-classes ...org.lunatechlabs.dotty.sudoku.CellMappingSuite:org.lunatechlabs.dotty.sudoku.ReductionRuleSuite: + Mapping row coordinates should resultin correct column& block coordinates 0.02s + Mapping column coordinates should resultin correct row& block coordinates 0.001s + Mapping block coordinates should resultin correct row& column coordinates 0.001s + Applying reduction rules should eliminate valuesin isolatedcomplete sets from occurrencesin other cells (First reduction rule) 0.045s + Applying reduction rules should eliminate valuesin isolatedcomplete sets of 5 values from occurrencesin other cells (First reduction rule) 0.001s + Applying reduction rules should eliminate valuesin 2 isolatedcomplete sets of 3 values from occurrencesin other cells (First reduction rule) 0.001s + Applying reduction rules should eliminate valuesin shadowedcomplete sets from occurrencesin the same cells (Second reduction rule) 0.001s + Applying reduction rules should eliminate valuesin shadowedcomplete (6 value) sets from occurrencesin the same cells (Second reduction rule) 0.001sSLF4J: A number (1) of logging calls during the initialization phase have been intercepted and areSLF4J: now being replayed. These are subject to the filtering rules of the underlying logging system.SLF4J: See also http://www.slf4j.org/codes.html#replayorg.lunatechlabs.dotty.sudoku.SudokuDetailProcessorSuite: + Sending no updates to a sudoku detail processor should resultin sending a SudokuDetailUnchanged message 0.007s + Sending an update to a fresh instance of the SudokuDetailProcessor that sets one cell to a single value should resultin sending an update that reflects this update 0.002s + Sending a series of subsequent Updates to a SudokuDetailProcessor should resultin sending updates and ultimatelyreturn no changes 0.003s[info] Passed: Total 11, Failed 0, Errors 0, Passed 11[success] Total time: 5 s, completed 24 Aug 2023, 08:30:54
Observe that all (11) tests passed successfully.
The Silver Searcher is a command line utility that combinesfind andgrep (and more) in asingle command.
Follow the installation instructionshere.
Instructions are provided in theIDE-Setup.md file in the root folder of the installedcourse.
About
Lunatech course - "Moving forward from Scala 2 to Scala 3"
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors8
Uh oh!
There was an error while loading.Please reload this page.