How to get an Option from index in Collection in Scala?
Solution 1:
Yes, you can lift your collection to a function Int => Option[A]
:
scala> List(1,2,3).lift
res0: Int => Option[Int] = <function1>
scala> List(1,2,3).lift(9)
res1: Option[Int] = None