Skip to content

Commit

Permalink
Example2.2.5.6.scala fixed
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Roehler <[email protected]>
  • Loading branch information
andreas-roehler committed Mar 5, 2024
1 parent 03dc29f commit 7ddd570
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
7 changes: 7 additions & 0 deletions chapter02/worksheets/Example2.2.5.6.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,10 @@ val a = toPairs(Seq("a", "b", "c"), "<nothing>")
val b: Seq[(String, String)] = List(("a","b"), ("c","<nothing>"))
assert(a == b)

// scala> :load Example2.2.5.6.scala
// :load Example2.2.5.6.scala
// def toPairs[A](xs: Seq[A], default: A): Seq[(A, A)]
// val result: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
// val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
// val a: Seq[(String, String)] = List((a,b), (c,<nothing>))
// val b: Seq[(String, String)] = List((a,b), (c,<nothing>))
12 changes: 10 additions & 2 deletions chapter02/worksheets/Example2.2.5.6_object.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ object ToPairsObject {
}
}

val result = toPairs(Seq(1, 2, 3, 4, 5, 6), -1)
val result = ToPairsObject.toPairs(Seq(1, 2, 3, 4, 5, 6), -1)
val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
assert(result == expected)

val a = toPairs(Seq("a", "b", "c"), "<nothing>")
val a = ToPairsObject.toPairs(Seq("a", "b", "c"), "<nothing>")
val b: Seq[(String, String)] = List(("a","b"), ("c","<nothing>"))
assert(a == b)

// scala> :load Example2.2.5.6_object.scala
// :load Example2.2.5.6_object.scala
// // defined object ToPairsObject
// val result: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
// val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
// val a: Seq[(String, String)] = List((a,b), (c,<nothing>))
// val b: Seq[(String, String)] = List((a,b), (c,<nothing>))
12 changes: 10 additions & 2 deletions chapter02/worksheets/Example2.2.5.6_object_main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,18 @@ object ToPairsObject {
}
}

val result = toPairs(Seq(1, 2, 3, 4, 5, 6), -1)
val result = ToPairsObject.toPairs(Seq(1, 2, 3, 4, 5, 6), -1)
val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
assert(result == expected)

val a = toPairs(Seq("a", "b", "c"), "<nothing>")
val a = ToPairsObject.toPairs(Seq("a", "b", "c"), "<nothing>")
val b: Seq[(String, String)] = List(("a","b"), ("c","<nothing>"))
assert(a == b)

// scala> :load Example2.2.5.6_object_main.scala
// :load Example2.2.5.6_object_main.scala
// // defined object ToPairsObject
// val result: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
// val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
// val a: Seq[(String, String)] = List((a,b), (c,<nothing>))
// val b: Seq[(String, String)] = List((a,b), (c,<nothing>))
17 changes: 8 additions & 9 deletions chapter02/worksheets/Example2.2.5.6_object_main_privat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,15 @@ object ToPairsObject {

}
def main(args: Array[String]): Unit = {
val result = ToPairsObject.toPairs(Seq(1, 2, 3), 4)
assert(result == expected)
val result = toPairs(Seq(1, 2, 3, 4, 5, 6), -1)
val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
assert(result == expected)

val a = toPairs(Seq("a", "b", "c"), "<nothing>")
val b: Seq[(String, String)] = List(("a","b"), ("c","<nothing>"))
assert(a == b)
println("a: %s".format(a))
}
}

val result = toPairs(Seq(1, 2, 3, 4, 5, 6), -1)
val expected: Seq[(Int, Int)] = List((1,2), (3,4), (5,6))
assert(result == expected)
}

val a = toPairs(Seq("a", "b", "c"), "<nothing>")
val b: Seq[(String, String)] = List(("a","b"), ("c","<nothing>"))
assert(a == b)

0 comments on commit 7ddd570

Please sign in to comment.