reversed sequence of output values in splitf-texpr

dev-validator
Matthew Butterick 11 years ago
parent 73c8d8db8b
commit e5208294e0

@ -194,7 +194,7 @@
;; function to split tag out of txexpr
(define+provide/contract (splitf-txexpr tx proc)
(txexpr? procedure? . -> . (values (listof txexpr-element?) txexpr?))
(txexpr? procedure? . -> . (values txexpr? (listof txexpr-element?)))
(define matches empty)
(define (do-extraction x)
(cond
@ -206,5 +206,5 @@
[(txexpr-elements? x) (filter-not empty? (map do-extraction x))]
[else x]))
(define tx-extracted (do-extraction tx)) ;; do this first to fill matches
(values (reverse matches) tx-extracted))
(values tx-extracted (reverse matches)))

@ -380,8 +380,8 @@ Be careful with the wider consequences of exclusion tests. When @racket[_exclude
(splitf-txexpr
[tx txexpr?]
[pred procedure?])
(values (listof txexpr-element?) txexpr?)]
Recursively descend through @racket[_txexpr] and extract all elements that match @racket[_pred]. Returns two values: a list of matching elements, and the @racket[_txexpr] with the elements removed. Sort of esoteric, but I've needed it more than once, so here it is.
(values txexpr? (listof txexpr-element?))]
Recursively descend through @racket[_txexpr] and extract all elements that match @racket[_pred]. Returns two values: a @racket[_txexpr] with the matching elements removed, and the list of matching elements. Sort of esoteric, but I've needed it more than once, so here it is.
@examples[#:eval my-eval
(define tx '(div "Wonderful day" (meta "weather" "good") "for a walk"))

@ -113,6 +113,5 @@
(define split-this-tx '(root (meta "foo" "bar") "hello" "world" (meta "foo2" "bar2")
(em "goodnight" "moon" (meta "foo3" "bar3"))))
(check-equal? (call-with-values (λ() (splitf-txexpr split-this-tx (λ(x) (and (txexpr? x) (equal? 'meta (car x)))))) list)
(list '((meta "foo" "bar") (meta "foo2" "bar2") (meta "foo3" "bar3"))
'(root "hello" "world" (em "goodnight" "moon"))))
(list '(root "hello" "world" (em "goodnight" "moon")) '((meta "foo" "bar") (meta "foo2" "bar2") (meta "foo3" "bar3"))))

Loading…
Cancel
Save