Ben Schmidt Ben Schmidt - 5 months ago 56
Scala Question

scala - one line convert string split to vals

I saw that following answer: Scala split string to tuple, but in the question the OP is asking for a string to a List. I would like to take a string, split it by some character, and convert it to a tuple so they can be saved as vals:

val (a,b,c) = "A.B.C".split(".").<toTupleMagic>

Is this possible? This would be a conversion from an
to a


It is unnecessary:

val Array(a, b, c) = "A.B.C".split('.')

Note that I converted the parameter to split from String to Char: if you pass a String, it is treated as a regex pattern, and . matches anything (so you'll get an array of empty strings back).

If you truly want to convert it to tuple, you can use Shapeless.