From 0407205bd20292ea09a57f3868e8f14fa7cea026 Mon Sep 17 00:00:00 2001 From: Manish Bansal Date: Fri, 4 Sep 2020 11:46:40 +0530 Subject: [PATCH 1/2] Update Vector-class.md Corrected typo --- _overviews/scala-book/vector-class.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/_overviews/scala-book/vector-class.md b/_overviews/scala-book/vector-class.md index 610aa2e41f..221b20b9a8 100644 --- a/_overviews/scala-book/vector-class.md +++ b/_overviews/scala-book/vector-class.md @@ -45,20 +45,20 @@ val b = a :+ 4 and this: ```scala -val b = a ++ Vector(4, 5) +val b = a ++: Vector(4, 5) ``` The REPL shows how this works: ```scala scala> val a = Vector(1,2,3) -a: Vector[Int] = List(1, 2, 3) +a: Vector[Int] = Vector(1, 2, 3) scala> val b = a :+ 4 -b: Vector[Int] = List(1, 2, 3, 4) +b: Vector[Int] = Vector(1, 2, 3, 4) -scala> val b = a ++ Vector(4, 5) -b: Vector[Int] = List(1, 2, 3, 4, 5) +scala> val b = a ++: Vector(4, 5) +b: Vector[Int] = Vector(1, 2, 3, 4, 5) ``` You can also *prepend* elements like this: @@ -77,10 +77,10 @@ Once again the REPL shows how this works: ```scala scala> val b = 0 +: a -b: Vector[Int] = List(0, 1, 2, 3) +b: Vector[Int] = Vector(0, 1, 2, 3) scala> val b = Vector(-1, 0) ++: a -b: Vector[Int] = List(-1, 0, 1, 2, 3) +b: Vector[Int] = Vector(-1, 0, 1, 2, 3) ``` Because `Vector` is not a linked-list (like `List`), you can prepend and append elements to it, and the speed of both approaches should be similar. From e34208a1ecd22959e2589cc46508e28ecce86ffd Mon Sep 17 00:00:00 2001 From: Manish Bansal Date: Thu, 17 Sep 2020 10:52:01 +0530 Subject: [PATCH 2/2] Incorporated review comments --- _overviews/scala-book/vector-class.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/_overviews/scala-book/vector-class.md b/_overviews/scala-book/vector-class.md index 221b20b9a8..15981e7904 100644 --- a/_overviews/scala-book/vector-class.md +++ b/_overviews/scala-book/vector-class.md @@ -45,7 +45,7 @@ val b = a :+ 4 and this: ```scala -val b = a ++: Vector(4, 5) +val b = a ++ Vector(4, 5) ``` The REPL shows how this works: @@ -57,7 +57,7 @@ a: Vector[Int] = Vector(1, 2, 3) scala> val b = a :+ 4 b: Vector[Int] = Vector(1, 2, 3, 4) -scala> val b = a ++: Vector(4, 5) +scala> val b = a ++ Vector(4, 5) b: Vector[Int] = Vector(1, 2, 3, 4, 5) ```