Might there be a elegant kotlin way to replace a s...
# announcements
d
Might there be a elegant kotlin way to replace a sublist with another sublist? Tried cutting the
toReplace
part out with this code snipped to replace it (the original type is not
Int
). But that doesn't look very clean. Also when you convert the list to a mutable list and remove the
toReplace
part it does'nt look very elegant.
Copy code
fun replaceInList(list: List<Int>, toReplace: List<Int>, replacement: List<Int>) = with(list) {
        subList(0, indexOf(toReplace.first)) + replacement + subList(indexOf(toReplace.last) + 1, size) 
    }