scala - How to safely split a string and check for both values -


if throws exception:

"".split('=')(1) 

is there idomatic way kind of operation safely in scala?

scala> "".split('=').lift(1) res0: option[string] = none  scala> "a=b".split('=').lift(1) res2: option[string] = some(b) 

note array after implicit conversion partial function indices values. can lift partial function, instead of value, or exception if not defined @ given argument, return some(value) or none respectively.


Comments