@@ -34,44 +34,56 @@ expect
34
34
expect
35
35
match = \input ->
36
36
when input is
37
- [.., 42 ] -> EndWith42
37
+ [.., 42 ] -> EndsWith42
38
38
_ -> Other
39
39
40
- (match [24 , 64 , 42 ] == EndWith42 )
41
- && (match [42 , 1 , 5 ] != EndWith42 )
40
+ (match [24 , 64 , 42 ] == EndsWith42 )
41
+ && (match [42 , 1 , 5 ] != EndsWith42 )
42
42
43
43
# Match a list that starts with a Foo tag
44
44
# followed by a Bar tag
45
45
expect
46
46
match = \input ->
47
47
when input is
48
- [Foo , Bar , ..] -> FooBar
48
+ [Foo , Bar , ..] -> StartsWithFooBar
49
49
_ -> Other
50
50
51
- (match [Foo , Bar , Bar ] == FooBar )
52
- && (match [Bar , Bar , Foo ] != FooBar )
51
+ (match [Foo , Bar , Bar ] == StartsWithFooBar )
52
+ && (match [Bar , Bar , Foo ] != StartsWithFooBar )
53
53
54
54
# Match a list with these exact elements:
55
55
# Foo, Bar, and then (Baz "Hi")
56
56
expect
57
57
match = \input ->
58
58
when input is
59
- [Foo , Bar , Baz " Hi" ] -> Bingo
59
+ [Foo , Bar , Baz " Hi" ] -> FooBarBazStr
60
60
_ -> Other
61
61
62
- (match [Foo , Bar , Baz " Hi" ] == Bingo )
63
- && (match [Foo , Bar ] != Bingo )
64
- && (match [Foo , Bar , Baz " Hi" , Blah ] != Bingo )
62
+ (match [Foo , Bar , Baz " Hi" ] == FooBarBazStr )
63
+ && (match [Foo , Bar ] != FooBarBazStr )
64
+ && (match [Foo , Bar , Baz " Hi" , Blah ] != FooBarBazStr )
65
65
66
66
# Match a list with Foo as its first element, and
67
67
# Count for its second element. Count holds a number,
68
68
# and we only match if that number is greater than 0.
69
69
expect
70
70
match = \input ->
71
71
when input is
72
- [Foo , Count num, ..] if num > 0 -> FooBar
72
+ [Foo , Count num, ..] if num > 0 -> FooCountIf
73
73
_ -> Other
74
74
75
- (match [Foo , Count 1 ] == FooBar )
76
- && (match [Foo , Count 0 ] != FooBar )
77
- && (match [Baz , Count 1 ] != FooBar )
75
+ (match [Foo , Count 1 ] == FooCountIf )
76
+ && (match [Foo , Count 0 ] != FooCountIf )
77
+ && (match [Baz , Count 1 ] != FooCountIf )
78
+
79
+ # Use `as` to create a variable equal to the part of the list that matches `..`
80
+ expect
81
+ match = \input ->
82
+ when input is
83
+ [head, .. as tail] -> HeadAndTail head tail
84
+ _ -> Other
85
+
86
+ (match [1 , 2 , 3 ] == HeadAndTail 1 [2 , 3 ])
87
+ && (match [1 , 2 ] == HeadAndTail 1 [2 ])
88
+ && (match [1 ] == HeadAndTail 1 [])
89
+ && (match [] == Other )
0 commit comments