Scala inconsistent sub-matrix

I am new to Scala. I see that there is a method slicefor arrays that can return a sequential slice, for example:

scala> "zero|one|two|three|four|five".split("\\|").slice(2,5)
res3: Array[String] = Array(two, three, four)

Is there syntactic sugar somewhere to accept an arbitrary, non-sequential, non-growing submatrix? Sort of:

scala> "zero|one|two|three|four|five".split("\\|").fictionalMethod(4,1,5)
res3: Array[String] = Array(four, one, five)
+4
source share
1 answer

The shortest line using only the standard library functions I can imagine will be

Array(4, 1, 5) map "zero|one|two|three|four|five".split("\\|")
+7
source

Source: https://habr.com/ru/post/1540854/


All Articles