utils: Add drop-first-last.
This commit is contained in:
parent
2af5656e71
commit
de80275a47
3 changed files with 20 additions and 3 deletions
|
@ -222,6 +222,16 @@ Reads a list of symbols from a string.
|
|||
(read-symbol-list "a b c")
|
||||
]}
|
||||
|
||||
@defproc[(drop-first-last (str String)) String]{
|
||||
|
||||
Removes the first and the last symbol of a given string.
|
||||
|
||||
Useful for removing the parentheses in string representations of lists.
|
||||
|
||||
@examples[#:eval utils-evaluator
|
||||
(drop-first-last "(a b)")
|
||||
]}
|
||||
|
||||
@section{Additional graph utilities}
|
||||
|
||||
@section{Pretty printing}
|
||||
|
|
|
@ -10,8 +10,7 @@
|
|||
|
||||
(provide
|
||||
;; Functions
|
||||
(contract-out [drop-first-last (-> string? string?)]
|
||||
[list-sets->list-strings (-> (listof (set/c any/c)) (listof string?))]
|
||||
(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?)]
|
||||
[update-vertices/unweighted (-> graph? (-> any/c any/c) graph?)]
|
||||
[update-graph (->* (graph?)
|
||||
|
|
10
utils.rkt
10
utils.rkt
|
@ -9,7 +9,7 @@
|
|||
extract-symbols
|
||||
any->string stringify-variable-mapping string->any map-sexp
|
||||
read-org-sexp unorg unstringify-pairs
|
||||
read-org-variable-mapping unorgv read-symbol-list
|
||||
read-org-variable-mapping unorgv read-symbol-list drop-first-last
|
||||
;; Syntax
|
||||
auto-hash-ref/explicit auto-hash-ref/:)
|
||||
|
||||
|
@ -262,3 +262,11 @@
|
|||
(module+ test
|
||||
(test-case "read-symbol-list"
|
||||
(check-equal? (read-symbol-list "a b c") '(a b c))))
|
||||
|
||||
(: drop-first-last (-> String String))
|
||||
(define (drop-first-last str)
|
||||
(substring str 1 (- (string-length str) 1)))
|
||||
|
||||
(module+ test
|
||||
(test-case "drop-first-last"
|
||||
(check-equal? (drop-first-last "(a b)") "a b")))
|
||||
|
|
Loading…
Reference in a new issue