Skip to content

Instantly share code, notes, and snippets.

@BasThomas

BasThomas/matrix.swift

Last active Nov 24, 2017
Embed
What would you like to do?
Switching on optional types
let o1nil: Int? = nil
let o1: Int? = 1
func switcher(_ a: Int?, _ b: Int?) {
switch (a, b) {
case (nil, nil):
print("nothing")
case (let thing?, nil):
print("lhs", thing)
case (nil, let thing?):
print("rhs", thing)
case (let left?, let right?):
print(left, right)
}
}
switcher(o1nil, o1nil) // nothing
switcher(o1, o1nil) // lhs 1
switcher(o1nil, o1) // rhs 1
switcher(o1, o1) // 1 1
@BasThomas

This comment has been minimized.

Copy link
Owner Author

@BasThomas BasThomas commented Nov 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment