Skip to content

Commit 2def921

Browse files
authored
add return type other than Unit onto the prepend() function in trait Bird
I don't think this page intends to have a Unit return type for prepend. Without it, prepend() doesn't do anything useful: ```scala> birdList.prepend(new EuropeanSwallow)``` returns Unit. So add the return type so prepend() does what the reader expects it to. With the suggested change, I get ```scala> birdList.prepend(new EuropeanSwallow) res16: Node[Bird] = ListNode(EuropeanSwallow(),ListNode(AfricanSwallow(),Nil()))```
1 parent 45a0338 commit 2def921

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

_tour/lower-type-bounds.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ To fix this, we need to flip the variance of the type of the parameter `elem` in
4242

4343
```tut
4444
trait Node[+B] {
45-
def prepend[U >: B](elem: U)
45+
def prepend[U >: B](elem: U): Node[U]
4646
}
4747
4848
case class ListNode[+B](h: B, t: Node[B]) extends Node[B] {

0 commit comments

Comments
 (0)