aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/library/lux/control/exception.lux
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/library/lux/control/exception.lux')
-rw-r--r--stdlib/source/library/lux/control/exception.lux42
1 files changed, 27 insertions, 15 deletions
diff --git a/stdlib/source/library/lux/control/exception.lux b/stdlib/source/library/lux/control/exception.lux
index 405c858a5..6d8b4e5e7 100644
--- a/stdlib/source/library/lux/control/exception.lux
+++ b/stdlib/source/library/lux/control/exception.lux
@@ -128,17 +128,25 @@
(list.repeat (n.+ (text.size header_separator)
largest_header_size))
(text.join_with "")
- (text\compose text.new_line))]
- (|> entries
- (list\map (function (_ [header message])
- (let [padding (|> " "
- (list.repeat (n.- (text.size header)
- largest_header_size))
- (text.join_with ""))]
- (|> message
- (text.replace_all text.new_line on_new_line)
- ($_ text\compose padding header header_separator)))))
- (text.join_with text.new_line))))
+ (text\compose text.new_line))
+ on_entry (: (-> [Text Text] Text)
+ (function (_ [header message])
+ (let [padding (|> " "
+ (list.repeat (n.- (text.size header)
+ largest_header_size))
+ (text.join_with ""))]
+ (|> message
+ (text.replace_all text.new_line on_new_line)
+ ($_ text\compose padding header header_separator)))))]
+ (case entries
+ #.Nil
+ ""
+
+ (#.Cons 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)))})
(wrap (list (` ((~! report') (list (~+ (|> entries
@@ -149,10 +157,14 @@
(All [a]
(-> (-> a Text) (List a) Text))
(|> entries
- list.enumeration
- (list\map (function (_ [index entry])
- [(n\encode index) (format entry)]))
- report'))
+ (list\fold (function (_ entry [index next])
+ [(inc index)
+ (#.Cons [(n\encode index) (format entry)]
+ next)])
+ [0 #.Nil])
+ product.right
+ list.reverse
+ ..report'))
(def: separator
(let [gap ($_ "lux text concat" text.new_line text.new_line)