@@ -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>
0 commit comments