In Dean Wampler's book, Programming Scala, 3rd Edition, there is an example with:
type Elem[X] = X match
case String => Char
case IterableOnce[t] => t
case Array[t] => t
case ? => X
summon[Elem[List[Int]] =:= Int]
summon[Elem[Nil.type] =:= Nothing]
It doesn't seem to be explained, at least in the surrounding context, why summon[Elem[Nil.type] =:= Nothing]
and not summon[Elem[Nil.type] =:= Nil.type]
. Why is this the case?
As suggested in the comments,
Nil
extendsList[Nothing]
, thus yourcase IterableOnce[t] => t
applies andElem[Nil.type] =:= Nothing
.