utils: Type pretty-print-set.

This commit is contained in:
Sergiu Ivanov 2022-02-03 23:56:28 +01:00
parent 211f39e91f
commit 2997319f1f
2 changed files with 18 additions and 3 deletions

View file

@ -246,6 +246,14 @@ those symbols.
(list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't))) (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't)))
]} ]}
@defproc[(pretty-print-set (s (Setof Any))) String]{
Pretty prints a set by listing its elements in alphabetic order.
@examples[#:eval utils-evaluator
(pretty-print-set (set 'a 'b 1))
]}
@section{Additional graph utilities} @section{Additional graph utilities}
@defproc[(dotit [graph Graph]) Void]{ @defproc[(dotit [graph Graph]) Void]{

View file

@ -21,7 +21,7 @@
extract-symbols any->string stringify-variable-mapping string->any extract-symbols any->string stringify-variable-mapping string->any
handle-org-booleans map-sexp read-org-sexp unorg unstringify-pairs handle-org-booleans map-sexp 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 dotit) list-sets->list-strings pretty-print-set dotit)
(define-type Variable Symbol) (define-type Variable Symbol)
(define-type (VariableMapping A) (Immutable-HashTable Variable A)) (define-type (VariableMapping A) (Immutable-HashTable Variable A))
@ -279,6 +279,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))
(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")))
(define dotit (compose display graphviz)) (define dotit (compose display graphviz))
) )
@ -287,7 +295,7 @@
extract-symbols any->string stringify-variable-mapping string->any extract-symbols any->string stringify-variable-mapping string->any
map-sexp read-org-sexp unorg unstringify-pairs map-sexp 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 dotit) list-sets->list-strings pretty-print-set dotit)
;;; Untyped section. ;;; Untyped section.
@ -299,7 +307,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))))]