I am trying to implement a way to take n
from a Scala List, but if n > list.length
, specify a default value. Something like takeOrElse.
Say, val l = List(4, 6, 10)
val taken = l.takeOrElse(5, 0) //List(4, 5, 6, 0, 0)
Is there a way to do this idiomatically without mutation and buffers? Appreciate your inputs.