concept mutability in category functional programming

This is an excerpt from Manning's book Grokking Functional Programming.
static List<String> replan(List<String> plan, String splitPoint, List<String> newEnding) { #A int newCityIndex = plan.indexOf(beforeCity); List<String> replanned = new ArrayList<>(plan); replanned.add(newCityIndex, newCity); return replanned; }
And voilà! That’s it, we have the working implementation which doesn’t have any problems related to the shared mutable state. We used the immutable Scala List and we can be sure that this function is pure, therefore we can trust that it will always behave in the same way!
3.19 Practicing immutable slicing and appending
It’s time to write some functions using immutable List in Scala:
Write the function called firstTwo which gets a list and returns a new list that contains only the first two elements of the incoming list. This assertion should be true:
firstTwo(List(“a”, “b”, “c”)) == List(“a”, “b”)1
Write the function called lastTwo which gets a list and returns a new list that contains only the last two elements of the incoming list. The below assertion should be true:
lastTwo(List(“a”, “b”, “c”)) == List(“b”, “c”)2
Write the function called movedFirstTwoToTheEnd which gets a list and returns a new list with first two elements of the incoming list moved to the end. The below assertion should be true:
movedFirstTwoToTheEnd(List(“a”, “b”, “c”)) == List(“c”, “a”, “b”)3
Write the function called insertedBeforeLast which gets a list and a new element. It returns a new list that has the element inserted before the last element of the incoming list. The below assertion should be true:
insertedBeforeLast(List(“a”, “b”), “c”) == List(“a”, “c”, “b”))4
