Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
extension Array {
private func reorderAndNormalized(swapElement indexA: Int, withElement indexB: Int, normalizeBlock: ((Int, Element) -> Element)) -> [Element]? {
guard indexA >= 0 && indexA < count else { return nil }
guard indexB >= 0 && indexB < count else { return nil }
var newItems = self
(newItems[indexA], newItems[indexB]) = (newItems[indexB], newItems[indexA])
return newItems.enumerate().map { index, item in
return normalizeBlock(index, item)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment