I'm new to Scala. I see that there's a slice
method for Arrays that can return a consecutive slice, like so:
scala> "zero|one|two|three|four|five".split("\\|").slice(2,5)
res3: Array[String] = Array(two, three, four)
Is there syntactic sugar somewhere for taking an arbitrary, non-consecutive, non-ascending sub-array? Something like:
scala> "zero|one|two|three|four|five".split("\\|").fictionalMethod(4,1,5)
res3: Array[String] = Array(four, one, five)
The shortest line using only standard library functions I can think of would be
Array(4, 1, 5) map "zero|one|two|three|four|five".split("\\|")
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