Skip to content

Commit 1e2dc0a

Browse files
authored
Merge pull request #58 from scala-exercises/enrique-2-13-1-update
Update to Scala 2.13.1
2 parents 6b00197 + 2049f22 commit 1e2dc0a

File tree

15 files changed

+38
-40
lines changed

15 files changed

+38
-40
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
language: scala
22
scala:
3-
- 2.12.10
3+
- 2.13.1
44
jdk:
55
- openjdk8
66
script:

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import ProjectPlugin.autoImport._
2-
val scalaExercisesV = "0.5.0-SNAPSHOT"
2+
val scalaExercisesV = "0.6.0-SNAPSHOT"
33

44
def dep(artifactId: String) = "org.scala-exercises" %% artifactId % scalaExercisesV
55

project/ProjectPlugin.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object ProjectPlugin extends AutoPlugin {
1515
object autoImport {
1616

1717
lazy val V = new {
18-
val scala212: String = "2.12.10"
18+
val scala213: String = "2.13.1"
1919
val shapeless: String = "2.3.3"
2020
val scalatest: String = "3.1.0"
2121
val scalatestplusScheck: String = "3.1.0.0-RC2"
@@ -39,7 +39,7 @@ object ProjectPlugin extends AutoPlugin {
3939
organizationEmail = "hello@47deg.com"
4040
),
4141
orgLicenseSetting := ApacheLicense,
42-
scalaVersion := V.scala212,
42+
scalaVersion := V.scala213,
4343
scalaOrganization := "org.scala-lang",
4444
resolvers ++= Seq(
4545
Resolver.mavenLocal,

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.2.8
1+
sbt.version=1.3.7

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ resolvers ++= Seq(
22
Resolver.sonatypeRepo("snapshots")
33
)
44

5-
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.5.0-SNAPSHOT")
5+
addSbtPlugin("org.scala-exercises" % "sbt-exercise" % "0.6.0-SNAPSHOT")
66
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.12.0-M3")

src/main/scala/fpinscalalib/ErrorHandlingSection.scala

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,17 @@ object ErrorHandlingSection
5555
case _ => None
5656
}
5757

58-
/**
59-
* We can look for our employees, and try to obtain their departments. We will assume that we won't find any errors,
60-
* and if it's the case, we don't have to worry as the computation will end there. Try to use `map` on the result of
61-
* calling `lookupByName` to create a function to obtain the department of each employee. Hint: to access the
62-
* optional employee, use Scala's underscore notation. i.e.:
63-
*
64-
* _.getOrElse(Employee("John", "Doe", None))
65-
*
66-
* Employee is defined as:
67-
*
68-
* case class Employee(name: String, department: String, manager: Option[String])
58+
/*
59+
We can look for our employees, and try to obtain their departments. We will assume that we won't find any errors,
60+
and if it's the case, we don't have to worry as the computation will end there. Try to use `map` on the result of
61+
calling `lookupByName` to create a function to obtain the department of each employee. Hint: to access the
62+
optional employee, use Scala's underscore notation. i.e.:
63+
64+
_.getOrElse(Employee("John", "Doe", None))
65+
66+
Employee is defined as:
67+
68+
case class Employee(name: String, department: String, manager: Option[String])
6969
*/
7070
def getDepartment: (Option[Employee]) => Option[String] = res0
7171

@@ -151,8 +151,8 @@ object ErrorHandlingSection
151151
* def variance(xs: Seq[Double]): Option[Double] =
152152
* mean(xs) flatMap (m => mean(xs.map(x => math.pow(x - m, 2))))
153153
* }}}
154-
*/
155-
/**
154+
*
155+
*
156156
* <b>Exercise 4.3:</b>
157157
*
158158
* Let's write a generic function to combine two `Option` values , so that if any of those values is `None`, the

src/main/scala/fpinscalalib/FunctionalDataStructuresSection.scala

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object FunctionalDataStructuresSection
5757
*
5858
* Take a look at the implementation of `List`'s `tail` function, and check its behaviour on the following cases:
5959
*/
60-
def listTakeAssert(res0: List[Int], res1: List[Int]) {
60+
def listTakeAssert(res0: List[Int], res1: List[Int]) = {
6161
def tail[A](l: List[A]): List[A] =
6262
l match {
6363
case Nil => sys.error("tail of empty list")
@@ -72,7 +72,7 @@ object FunctionalDataStructuresSection
7272
*
7373
* `setHead` follows a similar principle. Let's take a look at how it works:
7474
*/
75-
def listSetHeadAssert(res0: List[Int], res1: List[String]) {
75+
def listSetHeadAssert(res0: List[Int], res1: List[String]) = {
7676
def setHead[A](l: List[A], h: A): List[A] = l match {
7777
case Nil => sys.error("setHead on empty list")
7878
case Cons(_, t) => Cons(h, t)
@@ -91,7 +91,7 @@ object FunctionalDataStructuresSection
9191
res1: List[Int],
9292
res2: List[Int],
9393
res3: List[Int],
94-
res4: List[Int]) {
94+
res4: List[Int]) = {
9595
def drop[A](l: List[A], n: Int): List[A] =
9696
if (n <= 0) l
9797
else
@@ -113,7 +113,7 @@ object FunctionalDataStructuresSection
113113
* `dropWhile` extends the behaviour of `drop`, removing elements from the `List` prefix as long as they match a
114114
* predicate. Study its implementation and check how it works with the following examples:
115115
*/
116-
def listDropWhileAssert(res0: List[Int], res1: List[Int], res2: List[Int], res3: List[Int]) {
116+
def listDropWhileAssert(res0: List[Int], res1: List[Int], res2: List[Int], res3: List[Int]) = {
117117
def dropWhile[A](l: List[A], f: A => Boolean): List[A] =
118118
l match {
119119
case Cons(h, t) if f(h) => dropWhile(t, f)
@@ -131,7 +131,7 @@ object FunctionalDataStructuresSection
131131
*
132132
* `init` can be implemented in the same fashion, but cannot be implemented in constant time like `tail`:
133133
*/
134-
def listInitAssert(res0: List[Int], res1: List[Int]) {
134+
def listInitAssert(res0: List[Int], res1: List[Int]) = {
135135
def init[A](l: List[A]): List[A] =
136136
l match {
137137
case Nil => sys.error("init of empty list")
@@ -161,7 +161,7 @@ object FunctionalDataStructuresSection
161161
res7: Int,
162162
res8: Int,
163163
res9: Int,
164-
res10: Int) {
164+
res10: Int) = {
165165
foldRight(Cons(1, Cons(2, Cons(3, Nil))), 0)((x, y) => x + y) shouldBe 6
166166
res0 + foldRight(Cons(2, Cons(3, Nil)), 0)((x, y) => x + y) shouldBe 6
167167
res1 + res2 + foldRight(Cons(3, Nil), 0)((x, y) => x + y) shouldBe 6
@@ -175,9 +175,8 @@ object FunctionalDataStructuresSection
175175
* Now that we know how `foldRight` works, try to think about what happens when you pass `Nil` and `Cons` themselves
176176
* to `foldRight`.
177177
*/
178-
def listFoldRightNilConsAssert(res0: List[Int]) {
178+
def listFoldRightNilConsAssert(res0: List[Int]) =
179179
foldRight(List(1, 2, 3), Nil: List[Int])(Cons(_, _)) shouldBe res0
180-
}
181180

182181
/**
183182
* <b>Exercise 3.9:</b>

src/main/scala/fpinscalalib/GettingStartedWithFPSection.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ object GettingStartedWithFPSection
3333
* Try to fix the `loop` function inside `fib` so that it returns the correct values for each case in a tail-recursive
3434
* way. What should the missing expressions for the trivial case and the recursive call be?
3535
*/
36-
def fibAssert(res0: Int, res1: Int) {
36+
def fibAssert(res0: Int) = {
3737
def fib(n: Int): Int = {
3838
@annotation.tailrec
3939
def loop(n: Int, prev: Int, cur: Int): Int =
4040
if (n <= res0) prev
41-
else loop(n - res1, cur, prev + cur)
41+
else loop(n - 1, cur, prev + cur)
4242
loop(n, 0, 1)
4343
}
4444

src/main/scala/fpinscalalib/StrictnessAndLazinessSection.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ object StrictnessAndLazinessSection
3131
*
3232
* = Strict and non-strict functions =
3333
*
34+
* <b>NOTE:</b> This section is only for educational purposes. In Scala 2.13, scala.collection.immutable.Stream
35+
* is deprecated and scala.collection.immutable.LazyList is recommended for replacement. For more information,
36+
* check the Scala [[https://www.scala-lang.org/files/archive/api/2.13.1/scala/collection/immutable/Stream.html Stream]]
37+
* and [[https://www.scala-lang.org/files/archive/api/2.13.1/scala/collection/immutable/LazyList.html LazyList]]
38+
* documentation.
39+
*
3440
* <b>Exercise 5.1:</b>
3541
*
3642
* Now let's write a few helper functions to make inspecting streams easier, starting with a function to convert a

src/main/scala/fpinscalalib/customlib/functionalparallelism/ParHelper.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ package fpinscalalib.customlib.functionalparallelism
1313
// https://github.com/fpinscala/fpinscala/blob/a261989ae4e779b45c7176273dbd2349f487b7d1/answers/src/main/scala/fpinscala/parallelism/Par.scala
1414

1515
import java.util.concurrent._
16-
import language.implicitConversions
1716

1817
object Par {
1918
type Par[A] = ExecutorService => Future[A]

0 commit comments

Comments
 (0)