Last active
November 11, 2020 17:31
-
-
Save iluuu1994/096af29df86b2fe9b3da95c14595a45e 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
// Literal pattern | |
$foo is 1; | |
$foo is 'foo'; | |
$foo is SOME_CONST; // Ambiguous with class names :( | |
// Binding pattern | |
$foo is $bar; | |
// Type pattern | |
$foo is Foo; | |
$foo is int|string; | |
// Range pattern | |
$foo is 0..=10; | |
$foo is 0..<10; | |
$foo is >10; | |
$foo is >=10; | |
// Array pattern | |
$foo is [1, 2]; | |
$foo is ['foo' => 0..=10]; | |
$foo is ['foo', ...]; | |
// Object pattern | |
$foo is Foo { bar: $bar }; | |
$foo is Foo { $bar }; | |
// Logical pattern | |
$foo is Equatable and Hashable; | |
$foo is 1 or 2; | |
// Wildcard pattern | |
$foo is _ | |
// Regex pattern? | |
$foo is /^foo/; | |
// Expression pattern? | |
$foo is Foo { bar: (literallyAnything()) } | |
// Alternative to guards in other languages | |
match (foo) { | |
Foo { y } where y == literallyAnything() => ..., | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment