Last active
July 6, 2025 15:53
-
-
Save Amzd/6083711f5434336e496a3302421e02ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/// Switch statement helper to switch with function as input | |
func ~= <T>(value: T, block: (T) -> Bool) -> Bool { | |
block(value) | |
} | |
func ~= <T0, T1>(value: (T0, T1), block: (T0, T1) -> Bool) -> Bool { | |
block(value.0, value.1) | |
} | |
func ~= <T0, T1, T2>(value: (T0, T1, T2), block: (T0, T1, T2) -> Bool) -> Bool { | |
block(value.0, value.1, value.2) | |
} | |
func ~= <T0, T1, T2, T3>(value: (T0, T1, T2, T3), block: (T0, T1, T2, T3) -> Bool) -> Bool { | |
block(value.0, value.1, value.2, value.3) | |
} |
This file contains hidden or 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
func isValidValue(_ value: String) -> Bool { | |
// ... | |
} | |
switch isValidValue { | |
case "maybe this?": print("1") | |
case "what about this?": print("2") | |
case "or this?": print("3") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment