Skip to content

Commit f310f88

Browse files
committed
Make Task conform to Hashable
1 parent 827174c commit f310f88

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

ReactiveTask/Task.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,36 @@ extension Task: CustomStringConvertible {
5252
}
5353
}
5454

55+
extension Task: Hashable {
56+
public var hashValue: Int {
57+
var result = launchPath.hashValue ^ (workingDirectoryPath?.hashValue ?? 0)
58+
for argument in arguments {
59+
result ^= argument.hashValue
60+
}
61+
for (key, value) in environment ?? [:] {
62+
result ^= key.hashValue ^ value.hashValue
63+
}
64+
return result
65+
}
66+
}
67+
68+
private func ==<Key : Equatable, Value : Equatable>(lhs: [Key : Value]?, rhs: [Key : Value]?) -> Bool {
69+
switch (lhs, rhs) {
70+
case let (.Some(lhs), .Some(rhs)):
71+
return lhs == rhs
72+
73+
case (.None, .None):
74+
return true
75+
76+
default:
77+
return false
78+
}
79+
}
80+
81+
public func ==(lhs: Task, rhs: Task) -> Bool {
82+
return lhs.launchPath == rhs.launchPath && lhs.arguments == rhs.arguments && lhs.workingDirectoryPath == rhs.workingDirectoryPath && lhs.environment == rhs.environment
83+
}
84+
5585
/// A private class used to encapsulate a Unix pipe.
5686
private final class Pipe {
5787
/// The file descriptor for reading data.

0 commit comments

Comments
 (0)