diff options
Diffstat (limited to 'stdlib/source/library/lux/control/exception.lux')
-rw-r--r-- | stdlib/source/library/lux/control/exception.lux | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux index 22b882f85..c57c9877b 100644 --- a/stdlib/source/library/lux/control/exception.lux +++ b/stdlib/source/library/lux/control/exception.lux @@ -34,6 +34,7 @@ #constructor (-> a Text)}) (def: #export (match? exception error) + {#.doc (doc "Is this exception the cause of the error message?")} (All [e] (-> (Exception e) Text Bit)) (text.starts_with? (get@ #label exception) error)) @@ -100,7 +101,7 @@ (exception: #export some_exception) "" "Complex case:" - (exception: #export [optional type variables] (some_exception {optional Text} {arguments Int}) + (exception: #export [arbitrary type variables] (some_exception {optional Text} {arguments Int}) optional_body))} (macro.with_gensyms [g!descriptor] (do meta.monad @@ -140,29 +141,37 @@ (text.replace_all text.new_line on_new_line) ($_ text\compose padding header header_separator)))))] (case entries - #.Nil + #.End "" - (#.Cons head tail) + (#.Item head tail) (list\fold (function (_ post pre) ($_ text\compose pre text.new_line (on_entry post))) (on_entry head) tail)))) (syntax: #export (report {entries (p.many (s.tuple (p.and s.any s.any)))}) + {#.doc (doc "An error report." + (: Text + (report ["Row 0" value/0] + ["Row 1" value/1] + ,,, + ["Row N" value/N])))} (in (list (` ((~! report') (list (~+ (|> entries (list\map (function (_ [header message]) (` [(~ header) (~ message)]))))))))))) (def: #export (enumerate format entries) + {#.doc (doc "A numbered report of the entries on a list." + "NOTE: 0-based numbering.")} (All [a] (-> (-> a Text) (List a) Text)) (|> entries (list\fold (function (_ entry [index next]) [(inc index) - (#.Cons [(n\encode index) (format entry)] + (#.Item [(n\encode index) (format entry)] next)]) - [0 #.Nil]) + [0 #.End]) product.right list.reverse ..report')) @@ -183,6 +192,7 @@ error)) (def: #export (with exception message computation) + {#.doc (doc "If a computation fails, prepends the exception to the error.")} (All [e a] (-> (Exception e) e (Try a) (Try a))) (case computation (#//.Failure error) |