utils: Add pretty-print-set.
This commit is contained in:
parent
6ca2330a1f
commit
58327125eb
3 changed files with 16 additions and 2 deletions
|
@ -246,6 +246,13 @@ those symbols.
|
||||||
|
|
||||||
@section{Pretty printing}
|
@section{Pretty printing}
|
||||||
|
|
||||||
|
@defproc[(pretty-print-set (s (Setof Any))) String]{
|
||||||
|
|
||||||
|
Pretty print a set by listing its elements in alphabetic order.
|
||||||
|
|
||||||
|
@examples[#:eval utils-evaluator
|
||||||
|
(pretty-print-set (set 'a 'b 1))
|
||||||
|
]}
|
||||||
@section{Additional list and hash map utilities}
|
@section{Additional list and hash map utilities}
|
||||||
|
|
||||||
@section{Functions and procedures}
|
@section{Functions and procedures}
|
||||||
|
|
|
@ -16,7 +16,6 @@
|
||||||
(#:v-func (-> any/c any/c)
|
(#:v-func (-> any/c any/c)
|
||||||
#:e-func (-> any/c any/c))
|
#:e-func (-> any/c any/c))
|
||||||
graph?)]
|
graph?)]
|
||||||
[pretty-print-set (-> generic-set? string?)]
|
|
||||||
[collect-by-key (-> (listof any/c) (listof any/c) (values (listof any/c) (listof (listof any/c))))]
|
[collect-by-key (-> (listof any/c) (listof any/c) (values (listof any/c) (listof (listof any/c))))]
|
||||||
[collect-by-key/sets (-> (listof any/c) (listof any/c) (values (listof any/c) (listof (set/c any/c))))]
|
[collect-by-key/sets (-> (listof any/c) (listof any/c) (values (listof any/c) (listof (set/c any/c))))]
|
||||||
|
|
||||||
|
|
10
utils.rkt
10
utils.rkt
|
@ -10,7 +10,7 @@
|
||||||
any->string stringify-variable-mapping string->any map-sexp
|
any->string stringify-variable-mapping string->any map-sexp
|
||||||
read-org-sexp unorg unstringify-pairs
|
read-org-sexp unorg unstringify-pairs
|
||||||
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
||||||
list-sets->list-strings
|
list-sets->list-strings pretty-print-set
|
||||||
;; Syntax
|
;; Syntax
|
||||||
auto-hash-ref/explicit auto-hash-ref/:)
|
auto-hash-ref/explicit auto-hash-ref/:)
|
||||||
|
|
||||||
|
@ -283,3 +283,11 @@
|
||||||
(test-case "list-sets->list-strings"
|
(test-case "list-sets->list-strings"
|
||||||
(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)))
|
||||||
'("y x" "z" "" "t"))))
|
'("y x" "z" "" "t"))))
|
||||||
|
|
||||||
|
(: pretty-print-set (-> (Setof Any) String))
|
||||||
|
(define (pretty-print-set s)
|
||||||
|
(string-join (sort (set-map s any->string) string<?)))
|
||||||
|
|
||||||
|
(module+ test
|
||||||
|
(test-case "pretty-print-set"
|
||||||
|
(check-equal? (pretty-print-set (set 'a 'b 1)) "1 a b")))
|
||||||
|
|
Loading…
Reference in a new issue