on master help sign in
Text.Lexer: improve `choice`

Removed constraint requiring a non-empty list. Now, `choice` always fails if the list is empty.

commit6739b011a6db9eee7b1947eafe80524633e33b6c authorMichael Morgan <morgan.michael@me.com> dateMon 4 Sep 2017, 00:36 (9 years ago) parentf925538
1 file changed+4−4
libs/contrib/Text/Lexer.idr+4−4
libs/contrib/Text/Lexer.idr+4−4
@@ -113,11 +113,11 @@ export
113113many : Lexer -> Recognise False
114114many l = opt (some l)
115115
116−||| Recognise the first matching lexer from a non-empty list.
116+||| Recognise the first matching lexer from a Foldable. Always consumes input
117+||| if one of the options succeeds. Fails if the foldable is empty.
117118export
118−choice : (xs : List Lexer) -> {auto ok : NonEmpty xs} -> Lexer
119−choice (x :: []) = x
120−choice (x :: xs@(_ :: _)) = x <|> choice xs
119+choice : Foldable t => t Lexer -> Lexer
120+choice xs = foldr Alt Fail xs
121121
122122||| Recognise many instances of `l` until an instance of `end` is
123123||| encountered.