I started to learn Scala language and I have a question. How do you think, is it a right way to swap first and last x elements in List in a functional style?
def swap(l: List[Any], x: Int) = {
val l1 = l.take(x)
val l2 = l.slice(x, l.length - x)
val l3 = l.takeRight(x)
l3 ::: l2 ::: l1
}
It doesn't matter what happened if x would be more than half list length. I'm interested to find out algorithm.