Created
June 15, 2015 09:44
-
-
Save sooop/839bc282821784e2a116 to your computer and use it in GitHub Desktop.
Convenience Function for build Dictionary
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
let k = ["a", "b", "c", "d"] | |
let v = [1, 2, 3, 4] | |
let p = zip(k, v) | |
//: build fast dictionary from zipped object | |
func fastDictionary<K:Hashable, V>(data:Zip2<[K], [V]>) -> Dictionary<K, V> { | |
var result:[K:V] = [:] | |
for i in data { | |
result[i.0] = i.1 | |
} | |
return result | |
} | |
//: build fast dictionary from two sequence types. | |
func fastDictionary<K:Hashable, V>(s1:[K], s2:[V]) -> Dictionary<K, V> { | |
return fastDictionary(zip(s1, s2)) | |
} | |
let d = fastDictionary(k, v) | |
println(d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment