@@ -34,44 +34,56 @@ expect
3434expect
3535 match = \input ->
3636 when input is
37- [.., 42 ] -> EndWith42
37+ [.., 42 ] -> EndsWith42
3838 _ -> Other
3939
40- (match [24 , 64 , 42 ] == EndWith42 )
41- && (match [42 , 1 , 5 ] != EndWith42 )
40+ (match [24 , 64 , 42 ] == EndsWith42 )
41+ && (match [42 , 1 , 5 ] != EndsWith42 )
4242
4343# Match a list that starts with a Foo tag
4444# followed by a Bar tag
4545expect
4646 match = \input ->
4747 when input is
48- [Foo , Bar , ..] -> FooBar
48+ [Foo , Bar , ..] -> StartsWithFooBar
4949 _ -> Other
5050
51- (match [Foo , Bar , Bar ] == FooBar )
52- && (match [Bar , Bar , Foo ] != FooBar )
51+ (match [Foo , Bar , Bar ] == StartsWithFooBar )
52+ && (match [Bar , Bar , Foo ] != StartsWithFooBar )
5353
5454# Match a list with these exact elements:
5555# Foo, Bar, and then (Baz "Hi")
5656expect
5757 match = \input ->
5858 when input is
59- [Foo , Bar , Baz " Hi" ] -> Bingo
59+ [Foo , Bar , Baz " Hi" ] -> FooBarBazStr
6060 _ -> Other
6161
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 )
6565
6666# Match a list with Foo as its first element, and
6767# Count for its second element. Count holds a number,
6868# and we only match if that number is greater than 0.
6969expect
7070 match = \input ->
7171 when input is
72- [Foo , Count num, ..] if num > 0 -> FooBar
72+ [Foo , Count num, ..] if num > 0 -> FooCountIf
7373 _ -> Other
7474
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