git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
More pattern matching tests
commit6d5d9746e2d805491b8de57524aab3c5977852e5 authorPhil Freeman <paf31@cantab.net> dateWed 30 Oct 2013, 15:05 (13 years ago) parent4fdfe7d
2 files changed+18−3
README.md+3−3 examples/passing/Patterns.ps+15
README.md+3−3
@@ -435,9 +435,9 @@ The patterns above can be combined to create larger patterns.
435435For example:
436436
437437 f = \o -> case o of
438− { arr = [] } -> 0
439− { arr = [x:_], take = "head" } -> x
440− { arr = [_:xs], take = "tail" } -> sum xs
438+ { arr = [x:_], take = "car" } -> x
439+ { arr = [_,x:_], take = "cadr" } -> x
440+ _ -> 0
441441
442442## Named Patterns
443443
examples/passing/Patterns.ps+15
@@ -6,3 +6,18 @@ test = \x -> case x of
66f = \o -> case o of
77 { foo = "Foo" } -> o.bar
88 _ -> 0
9+
10+g = \o -> case o of
11+ { arr = [x : xs], take = "car" } -> x
12+ { arr = [_, x : xs], take = "cadr" } -> x
13+ _ -> 0
14+
15+
16+h = \o -> case o of
17+ a@[_,_,_] -> a
18+ _ -> []
19+
20+isDesc = \o -> case o of
21+ [x, y] | x > y -> true
22+ _ -> false
23+