Created
June 8, 2016 09:19
-
-
Save seivan/321171a17b69d7c4296b78e627b7cb10 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
let keys = [ | |
1 : ["value" : "FirstValue", "dependencies" : Set(arrayLiteral: 2)], | |
2 : ["value" : "SecondValue", "dependencies" : Set(arrayLiteral: 1)], | |
] | |
keys.reduce(Dictionary<Set<Int>, Set<Int>>()) { (allDependencies, keyValueTuple) in | |
let (key, content) = keyValueTuple | |
var dependencyGraph = allDependencies | |
let dependencyKey = (content["dependencies"] as! Set<Int>).union([key]) | |
dependencyGraph[dependencyKey] = dependencyGraph[dependencyKey]?.union([key]) ?? [key] | |
if dependencyGraph[dependencyKey] == dependencyKey { | |
print("Dependency has been fulfilled for \(key) with list \(dependencyGraph[dependencyKey])") | |
} | |
else { | |
print("Dependency is not fulfilled yet for key: \(key)") | |
} | |
return dependencyGraph | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment