scala - Access element of an Array and return a monad? -


if access index outside bounds of array, arrayindexoutofboundsexception, eg:

val = new array[string](3) a(4) java.lang.arrayindexoutofboundsexception: 4 

is there method return monad instead (eg: option)? , why doesn't default collections apply method array support this?

you can use lift:

a.lift(4) // none a.lift(2) // some(null) 

array[t] partialfunction[int, t] , lift creates function[int, option[t]] index option of element type.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -