From 4ff203c30c96ce5a00fffe323a3bec3097d788ed Mon Sep 17 00:00:00 2001 From: Andreas Roehler Date: Fri, 24 Nov 2023 14:56:56 +0100 Subject: [PATCH 1/2] #11, solution2.1.7.5.scala Signed-off-by: Andreas Roehler --- chapter02/worksheets/solution2.1.7.5.scala | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 chapter02/worksheets/solution2.1.7.5.scala diff --git a/chapter02/worksheets/solution2.1.7.5.scala b/chapter02/worksheets/solution2.1.7.5.scala new file mode 100644 index 0000000..2e50f02 --- /dev/null +++ b/chapter02/worksheets/solution2.1.7.5.scala @@ -0,0 +1,7 @@ +val p = Seq("a", "b", "c") +val q = Seq(10, -1, 5) + +p.zip(q).toList.sortBy(_._2).map{case (x, y) => x} +// res10: List[String] = List(b, c, a) + + From d775aae07f116f6e095489b219235dccdc0aafa4 Mon Sep 17 00:00:00 2001 From: Andreas Roehler Date: Sat, 25 Nov 2023 11:11:49 +0100 Subject: [PATCH 2/2] redundant toList removed Signed-off-by: Andreas Roehler --- chapter02/worksheets/solution2.1.7.5.scala | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/chapter02/worksheets/solution2.1.7.5.scala b/chapter02/worksheets/solution2.1.7.5.scala index 2e50f02..0eb85d0 100644 --- a/chapter02/worksheets/solution2.1.7.5.scala +++ b/chapter02/worksheets/solution2.1.7.5.scala @@ -1,7 +1,10 @@ val p = Seq("a", "b", "c") val q = Seq(10, -1, 5) -p.zip(q).toList.sortBy(_._2).map{case (x, y) => x} -// res10: List[String] = List(b, c, a) - +p.zip(q).sortBy(_._2).map{case (x, y) => x} +// scala> :load solution2.1.7.5.scala +// Loading solution2.1.7.5.scala... +// p: Seq[String] = List(a, b, c) +// q: Seq[Int] = List(10, -1, 5) +// res0: Seq[String] = List(b, c, a)