Skip to content

Instantly share code, notes, and snippets.

@Nirma
Created August 3, 2016 11:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nirma/a2b9cce61732a7893bd4881854c00cf0 to your computer and use it in GitHub Desktop.
Save Nirma/a2b9cce61732a7893bd4881854c00cf0 to your computer and use it in GitHub Desktop.
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