Reading from a vector, I want to return none when trying to read an index that is out of bounds and some otherwise. Is there a standard method for this?
You can use lift
:
val v = Vector(1, 2, 3)
v.lift(0) //Some(1)
v.lift(5) //None
note this works for any partial function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With