You make your life much more difficult by introducing variables at every opportunity. Do not do that!
Both parameters that you specified are clean enough if you do not enter temporary variables:
val l2 = change(l.head) :: l.tail
val l2 = l.update(0, change(l.head))
Empty lists are also not safe, but
val l2 = l.take(1).map(change) ::: l.drop(1)
there is.
:
class ReheadableList[A](xs: List[A]) {
def rehead[B >: A](f: A => B) = xs.take(1).map(f) ::: xs.drop(1)
}
implicit def lists_can_be_reheaded[A](xs: List[A]) = new ReheadableList(xs)
( - , ).
val l2 = l.rehead(change)