Skip to content

Commit 4c93318

Browse files
committed
Add temporary optional equality operator
Signed-off-by: Vihan <vihan+github@vihan.org>
1 parent 6823908 commit 4c93318

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Optional.vsl

+14
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ public struct Optional<Type> {
1212
self.hasValue = true
1313
self.value = value
1414
}
15+
16+
/// Comparison overloads for optionals where T implements equatable. If you
17+
/// wish to check for nil otherwise you can use the `===` operator which
18+
/// checks reference equality. Internally, all VSL `nil` instances stem from
19+
/// the same value
20+
public static func ==(lhs: Optional<Type>, rhs: Optional<Type>) -> Bool {
21+
if lhs.hasValue == true && rhs.hasValue == true {
22+
// Otherwise compare the underlying values
23+
return true // TODO: Implement with interfaces
24+
} else {
25+
// If one is nil then both must be nil for this to be true
26+
return lhs.hasValue == rhs.hasValue
27+
}
28+
}
1529
}

0 commit comments

Comments
 (0)