/** * Returns a new List with the element at [fromIndex] moved to [toIndex] */ private fun List.move(fromIndex: Int, toIndex: Int) = this.mapIndexed { index, element -> when { index == toIndex -> this[fromIndex] fromIndex < toIndex && index in fromIndex..toIndex -> this[index + 1] fromIndex > toIndex && index in toIndex..fromIndex -> this[index - 1] else -> element } } /** * Returns a pair of the head and the tail of this iterable. */ fun Iterable.pop(): Pair> = this.first() to this.drop(1)