Skip to content

Commit

Permalink
Merge pull request #60 from DanielaSfregola/unit2_migration_scala3
Browse files Browse the repository at this point in the history
[Unit 2] Migration to Scala 3
  • Loading branch information
DanielaSfregola committed Feb 21, 2021
2 parents 459bf8b + bd8ab1e commit ab95145
Show file tree
Hide file tree
Showing 23 changed files with 67 additions and 15 deletions.
2 changes: 1 addition & 1 deletion unit2/lesson10/build.sbt
Expand Up @@ -2,4 +2,4 @@ name := "get-programming-with-scala-lesson10"

version := "0.1"

scalaVersion := "2.12.5"
scalaVersion := "3.0.0-RC1"
2 changes: 1 addition & 1 deletion unit2/lesson10/project/build.properties
@@ -1 +1 @@
sbt.version = 1.4.2
sbt.version = 1.4.7
1 change: 1 addition & 0 deletions unit2/lesson10/project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
2 changes: 1 addition & 1 deletion unit2/lesson11/build.sbt
Expand Up @@ -2,4 +2,4 @@ name := "get-programming-with-scala-lesson11"

version := "0.1"

scalaVersion := "2.12.5"
scalaVersion := "3.0.0-RC1"
2 changes: 1 addition & 1 deletion unit2/lesson11/project/build.properties
@@ -1 +1 @@
sbt.version = 1.4.2
sbt.version = 1.4.7
1 change: 1 addition & 0 deletions unit2/lesson11/project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
2 changes: 1 addition & 1 deletion unit2/lesson11/src/main/scala/listings/Listing-11.2.sc
Expand Up @@ -2,7 +2,7 @@
* public class MySingleton {
* private static MySingleton instance = null;
**
*protected MySingleton() {}
*private MySingleton() {}
**
*public static MySingleton getInstance() {
* if(instance == null) {
Expand Down
Expand Up @@ -13,7 +13,7 @@ new MySnippet
// scala> new MySnippet
// <console>:11: error: not found: type MySnippet
//
// The first statement successfully defines an object called “MySnippet”.
// The first expression successfully defines an object called “MySnippet”.
// The second one is incorrect: you cannot request the creation of an object.
// When using the keyword new the compiler looks for a class or type called “MySnippet”:
// an object is neither, so the compiler rejects it with a missing type error.
2 changes: 1 addition & 1 deletion unit2/lesson12/build.sbt
Expand Up @@ -2,4 +2,4 @@ name := "get-programming-with-scala-lesson12"

version := "0.1"

scalaVersion := "2.12.6"
scalaVersion := "3.0.0-RC1"
2 changes: 1 addition & 1 deletion unit2/lesson12/project/build.properties
@@ -1 +1 @@
sbt.version = 1.4.2
sbt.version = 1.4.7
1 change: 1 addition & 0 deletions unit2/lesson12/project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
5 changes: 3 additions & 2 deletions unit2/lesson12/src/main/scala/listings/Listing-12.2.sc
@@ -1,5 +1,6 @@
trait Nameable {

def name: String

}

// which you can rewrite in Scala 3 as:
// trait Nameable(name: String)
21 changes: 21 additions & 0 deletions unit2/lesson12/src/main/scala/listings/Listing-12.4.sc
Expand Up @@ -19,3 +19,24 @@ class Dog(val name: String) extends Animal with Nameable {

def move(x: Int, y: Int) = "let's go to ($x, $y)!"
}

class Cat extends Animal {

override val sleep = "sleepy cat!"

def eat(food: String) = s"the cat is eating $food"

def move(x: Int, y: Int) = s"the cat is moving to ($x,$y)"
}


val tiggerTheDog = new Dog("Tigger")
val cat = new Cat

def feedTreat(animal: Animal) = animal.eat("treat")
feedTreat(tiggerTheDog)
feedTreat(cat)

def welcome(nameable: Nameable) = println(s"Hi, ${nameable.name}!")
welcome(tiggerTheDog)
welcome(cat) // Doesn't compile - Cat doesn't extend Nameable
8 changes: 8 additions & 0 deletions unit2/lesson12/src/main/scala/listings/Listing-12.6.sc
@@ -0,0 +1,8 @@
enum Suit {
case Clubs, Diamonds, Hearts, Spades
}


Suit.Hearts
Suit.values
Suit.fromOrdinal(0)
9 changes: 9 additions & 0 deletions unit2/lesson12/src/main/scala/listings/Listing-12.7.sc
@@ -0,0 +1,9 @@
enum Country(val code: String) {
case Italy extends Country("IT")
case UnitedKingdom extends Country("UK")
case UnitedStates extends Country("US")
case Japan extends Country("JP")
}


Country.Italy.code
9 changes: 9 additions & 0 deletions unit2/lesson12/src/main/scala/quickchecks/QuickCheck-12.4.sc
@@ -0,0 +1,9 @@
// In Quick Check 12.3, you have implemented a sealed trait Currency with three implementations:
// re-implementing using enumeration syntax for Scala 3.


// ANSWER

enum Currency {
case USD, CAD, EUR
}
2 changes: 1 addition & 1 deletion unit2/lesson13/build.sbt
Expand Up @@ -2,4 +2,4 @@ name := "get-programming-with-scala-lesson13"

version := "0.1"

scalaVersion := "2.12.6"
scalaVersion := "3.0.0-RC1"
2 changes: 1 addition & 1 deletion unit2/lesson13/project/build.properties
@@ -1 +1 @@
sbt.version = 1.4.2
sbt.version = 1.4.7
1 change: 1 addition & 0 deletions unit2/lesson13/project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
2 changes: 1 addition & 1 deletion unit2/lesson9/build.sbt
Expand Up @@ -2,4 +2,4 @@ name := "get-programming-with-scala-lesson9"

version := "0.1"

scalaVersion := "2.12.5"
scalaVersion := "3.0.0-RC1"
2 changes: 1 addition & 1 deletion unit2/lesson9/project/build.properties
@@ -1 +1 @@
sbt.version = 1.4.2
sbt.version = 1.4.7
1 change: 1 addition & 0 deletions unit2/lesson9/project/plugins.sbt
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.3")
1 change: 0 additions & 1 deletion unit2/lesson9/src/main/scala/listings/Listing-9.4.md

This file was deleted.

0 comments on commit ab95145

Please sign in to comment.