Generalize the type of pretty-print-set.

This commit is contained in:
Sergiu Ivanov 2023-08-17 16:58:21 +02:00
parent 5bc062af54
commit 0e364eb52d
2 changed files with 5 additions and 3 deletions

View file

@ -366,12 +366,13 @@ those symbols.
@section[#:tag "utils_Pretty_printing"]{Pretty printing} @section[#:tag "utils_Pretty_printing"]{Pretty printing}
@defproc[(pretty-print-set (s (Setof Any))) String]{ @defproc[(pretty-print-set [s (U (Setof Any) (Listof Any))]) String]{
Pretty prints a set by listing its elements in alphabetic order. Pretty prints a set by listing its elements in alphabetic order.
@ex[ @ex[
(pretty-print-set (set 'a 'b 1)) (pretty-print-set (set 'a 'b 1))
(pretty-print-set (list 'a 'b 1))
]} ]}
@defproc[(pretty-print-set-sets [ms (U (Listof (Setof Any)) (Setof (Setof Any)))]) @defproc[(pretty-print-set-sets [ms (U (Listof (Setof Any)) (Setof (Setof Any)))])

View file

@ -347,13 +347,14 @@
(check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) (check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't)))
'("x y" "z" "" "t")))) '("x y" "z" "" "t"))))
(: pretty-print-set (-> (Setof Any) String)) (: pretty-print-set (-> (U (Setof Any) (Listof Any)) String))
(define (pretty-print-set s) (define (pretty-print-set s)
(string-join (sort (set-map s any->string) string<?))) (string-join (sort (set-map s any->string) string<?)))
(module+ test (module+ test
(test-case "pretty-print-set" (test-case "pretty-print-set"
(check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b"))) (check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b")
(check-equal? (pretty-print-set (list 'a 'b 1)) "1 a b")))
(: pretty-print-set-sets (-> (U (Setof (Setof Any)) (: pretty-print-set-sets (-> (U (Setof (Setof Any))
(Listof (Setof Any))) (Listof (Setof Any)))