diff --git a/chapter02/worksheets/Example2.2.5.6.scala b/chapter02/worksheets/Example2.2.5.6.scala index 3e09d81..1f317aa 100644 --- a/chapter02/worksheets/Example2.2.5.6.scala +++ b/chapter02/worksheets/Example2.2.5.6.scala @@ -42,3 +42,10 @@ val a = toPairs(Seq("a", "b", "c"), "") val b: Seq[(String, String)] = List(("a","b"), ("c","")) 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,)) +// val b: Seq[(String, String)] = List((a,b), (c,)) diff --git a/chapter02/worksheets/Example2.2.5.6_object.scala b/chapter02/worksheets/Example2.2.5.6_object.scala index 42865f6..db62bfb 100644 --- a/chapter02/worksheets/Example2.2.5.6_object.scala +++ b/chapter02/worksheets/Example2.2.5.6_object.scala @@ -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"), "") +val a = ToPairsObject.toPairs(Seq("a", "b", "c"), "") val b: Seq[(String, String)] = List(("a","b"), ("c","")) 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,)) +// val b: Seq[(String, String)] = List((a,b), (c,)) diff --git a/chapter02/worksheets/Example2.2.5.6_object_main.scala b/chapter02/worksheets/Example2.2.5.6_object_main.scala index 423b5ab..6c88f1d 100644 --- a/chapter02/worksheets/Example2.2.5.6_object_main.scala +++ b/chapter02/worksheets/Example2.2.5.6_object_main.scala @@ -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"), "") +val a = ToPairsObject.toPairs(Seq("a", "b", "c"), "") val b: Seq[(String, String)] = List(("a","b"), ("c","")) 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,)) +// val b: Seq[(String, String)] = List((a,b), (c,)) diff --git a/chapter02/worksheets/Example2.2.5.6_object_main_privat.scala b/chapter02/worksheets/Example2.2.5.6_object_main_privat.scala index 203a72e..d267601 100644 --- a/chapter02/worksheets/Example2.2.5.6_object_main_privat.scala +++ b/chapter02/worksheets/Example2.2.5.6_object_main_privat.scala @@ -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"), "") + val b: Seq[(String, String)] = List(("a","b"), ("c","")) + 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"), "") -val b: Seq[(String, String)] = List(("a","b"), ("c","")) -assert(a == b)