Created
July 25, 2016 14:08
-
-
Save maxsz/267eb54c672116f4245fdd52b5a5da7d to your computer and use it in GitHub Desktop.
Swift SequenceType Extensions
This file contains hidden or 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 SequenceType { | |
// Index an array with a property. | |
@warn_unused_result | |
func index<T: Hashable>(@noescape by indexFunc: (Generator.Element -> T)) -> [T: Generator.Element] { | |
var dict: [T: Generator.Element] = [:] | |
for element in self { | |
let index = indexFunc(element) | |
dict[index] = element | |
} | |
return dict | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment