dictionary - Scala map split input to int and string? -


normally if reading line of input stdin looks "100 200" can store them both ints line:

val array(a, b) = readline.split(" ").map(_.toint); 

but if a integer , b string?

you cannot store values of different types homogeneous container such array. if know cardinality, store them in separate variables.

val input = "100 foo" val array(a, b) = input.split(" ")  val p1 = scala.util.try(a.toint) val p2 = b 

i used scala.util.try because toint may fail , throw exception


Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -