utils: Add list-sets->list-strings.

This commit is contained in:
Sergiu Ivanov 2020-12-23 13:52:38 +01:00
parent b3408a7bfe
commit 6ca2330a1f
3 changed files with 25 additions and 3 deletions

View file

@ -1,6 +1,7 @@
#lang scribble/manual
@(require scribble/example racket/sandbox
(for-label typed/racket/base graph "../utils.rkt"))
(for-label typed/racket/base graph "../utils.rkt"
(only-in racket/set set)))
@title[#:tag "utils"]{dds/utils: Various Utilities}
@ -232,6 +233,15 @@ Useful for removing the parentheses in string representations of lists.
(drop-first-last "(a b)")
]}
@defproc[(list-sets->list-strings (lst (Listof (Setof Any)))) (Listof String)]{
Converts a list of sets of symbols to a list of strings containing
those symbols.
@examples[#:eval utils-evaluator
(list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't)))
]}
@section{Additional graph utilities}
@section{Pretty printing}

View file

@ -10,8 +10,7 @@
(provide
;; Functions
(contract-out [list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))]
[pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)]
(contract-out [pretty-print-set-sets (-> (set/c (set/c symbol?) #:kind 'dont-care) string?)]
[update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
[update-graph (->* (graph?)
(#:v-func (-> any/c any/c)

View file

@ -10,6 +10,7 @@
any->string stringify-variable-mapping string->any map-sexp
read-org-sexp unorg unstringify-pairs
read-org-variable-mapping unorgv read-symbol-list drop-first-last
list-sets->list-strings
;; Syntax
auto-hash-ref/explicit auto-hash-ref/:)
@ -270,3 +271,15 @@
(module+ test
(test-case "drop-first-last"
(check-equal? (drop-first-last "(a b)") "a b")))
(: list-sets->list-strings (-> (Listof (Setof Any)) (Listof String)))
(define (list-sets->list-strings lst)
(map (multi-compose drop-first-last
any->string
(λ ([x : (Setof Any)])
(set->list x))) lst))
(module+ test
(test-case "list-sets->list-strings"
(check-equal? (list-sets->list-strings (list (set 'x 'y) (set 'z) (set) (set 't)))
'("y x" "z" "" "t"))))