Is there a way, only using the Scala collection API, to get an Option in a List when trying to get an element by its index?
I'm looking for the equivalent of this function, does it exist?
def optionalValue[T](l: List[T], index: Int) = {
if (l.size < (index+1)) None
else Some(l(index))
}
Thanks
Yes, you can lift your collection to a function
Int => Option[A]
: