2022-03-02 11:05:18 +00:00
|
|
|
func foo(x):
|
2022-12-26 16:24:17 +00:00
|
|
|
match x:
|
|
|
|
{"key1": "value1", "key2": "value2"}:
|
|
|
|
print('{"key1": "value1", "key2": "value2"}')
|
|
|
|
{"key1": "value1", "key2"}:
|
|
|
|
print('{"key1": "value1", "key2"}')
|
|
|
|
{"key1", "key2": "value2"}:
|
|
|
|
print('{"key1", "key2": "value2"}')
|
|
|
|
{"key1", "key2"}:
|
|
|
|
print('{"key1", "key2"}')
|
|
|
|
{"key1": "value1"}:
|
|
|
|
print('{"key1": "value1"}')
|
|
|
|
{"key1"}:
|
|
|
|
print('{"key1"}')
|
|
|
|
_:
|
|
|
|
print("wildcard")
|
2022-03-02 11:05:18 +00:00
|
|
|
|
|
|
|
func bar(x):
|
2022-12-26 16:24:17 +00:00
|
|
|
match x:
|
|
|
|
{0}:
|
|
|
|
print("0")
|
|
|
|
{1}:
|
|
|
|
print("1")
|
|
|
|
{2}:
|
|
|
|
print("2")
|
|
|
|
_:
|
|
|
|
print("wildcard")
|
2022-03-02 11:05:18 +00:00
|
|
|
|
2024-04-08 02:13:10 +00:00
|
|
|
func baz(x):
|
|
|
|
match x:
|
|
|
|
{
|
|
|
|
"key1": "value1"
|
|
|
|
}:
|
|
|
|
print('multiline {"key1": "value1"}')
|
|
|
|
{
|
|
|
|
"key2": "value2",
|
|
|
|
}:
|
|
|
|
print('multiline {"key2": "value2",}')
|
|
|
|
{
|
|
|
|
"key3": {
|
|
|
|
"key1",
|
|
|
|
..,
|
|
|
|
},
|
|
|
|
}:
|
|
|
|
print('multiline {"key3": {"key1", ..,},}')
|
|
|
|
|
2022-03-02 11:05:18 +00:00
|
|
|
func test():
|
2022-12-26 16:24:17 +00:00
|
|
|
foo({"key1": "value1", "key2": "value2"})
|
|
|
|
foo({"key1": "value1", "key2": ""})
|
|
|
|
foo({"key1": "", "key2": "value2"})
|
|
|
|
foo({"key1": "", "key2": ""})
|
|
|
|
foo({"key1": "value1"})
|
|
|
|
foo({"key1": ""})
|
|
|
|
foo({"key1": "value1", "key2": "value2", "key3": "value3"})
|
|
|
|
foo({"key1": "value1", "key3": ""})
|
|
|
|
foo({"key2": "value2"})
|
|
|
|
foo({"key3": ""})
|
|
|
|
bar({0: "0"})
|
|
|
|
bar({1: "1"})
|
|
|
|
bar({2: "2"})
|
|
|
|
bar({3: "3"})
|
2024-04-08 02:13:10 +00:00
|
|
|
baz({"key1": "value1"})
|
|
|
|
baz({"key2": "value2"})
|
|
|
|
baz({"key3": {"key1": "value1", "key2": "value2"}})
|