Skip to content

Commit ef9f68f

Browse files
authored
Concatenate and add elements examples for Lists.scala
1 parent b81f080 commit ef9f68f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/main/scala/stdlib/Lists.scala

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,30 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions.
159159
val a = (1 to 5).toList
160160
a should be(res0)
161161
}
162+
163+
/** You can add elements to a List and get a new List:
164+
*/
165+
def addElementsLists(
166+
res0: List[Int],
167+
res1: List[Int]) {
168+
val a = List(1, 3, 5, 7)
169+
170+
0 :: a should be(res0)
171+
a :: 9 should be(res1)
172+
}
173+
174+
/** Lists can be concatened and Nil is an empty List:
175+
*/
176+
def concatenateLists(
177+
res0: List[Int],
178+
res1: List[Int]) {
179+
val head = List(1, 3)
180+
val tail = List(5, 7)
181+
182+
head ::: tail should be(res0)
183+
head ::: Nil should be(res1)
184+
}
185+
162186

163187
/** Lists reuse their tails:
164188
*/
@@ -179,5 +203,4 @@ object Lists extends FlatSpec with Matchers with org.scalaexercises.definitions.
179203
b.tail should be(res4)
180204
c.tail should be(res5)
181205
}
182-
183206
}

0 commit comments

Comments
 (0)