I’m struggling with the simple-linked-list exercise … and I’m not sure that it’s just me … there aren’t that many submissions. It’s marked as “medium”, but it feels “hard.”
Some thoughts … I’m not a scala expert, so I’m not sure.
- Going in sequence, this is practically the first exercise (aside from Forth) that uses
trait
; it’s not an easy introduction. - Add to this, the trait given in the problem makes it challenging to get to an idiomatic solution, and it is unclear that modifying the prompted trait is “okay.”
So, that said, … modifying the exercise might smooth out the challenge
- Changing the trait to be covariant
SimpleLinkedList[+T]
(from invariant[T]
) - Changing the
add
method have a lower bounddef add[U >: T](item: U) ...
-
add
is harder to implement thanprepend
(getting the list ordering right is tricky and well… recursion hurts my brain) … if that’s a pedagogic goal, then great, but maybe a less ambitious target would be nice, and then maybe a harder challenge later in the series foradd
/append
andreverse