Created
August 3, 2016 11:47
-
-
Save Nirma/a2b9cce61732a7893bd4881854c00cf0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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