add `other-siblings`

pull/148/head
Matthew Butterick 8 years ago
parent 80517b1bb4
commit fcc84a810c

@ -175,6 +175,23 @@
(check-false (siblings 'invalid-key test-pagetree)))
(define+provide/contract (other-siblings pnish [pt-or-path (current-pagetree)])
(((or/c #f pagenodeish?)) ((or/c pagetree? pathish?)) . ->* . (or/c #f pagenodes?))
(define sibs (for/list ([sib (in-list (or (siblings pnish pt-or-path) empty))]
#:unless (eq? sib (->pagenode pnish)))
sib))
(and (pair? sibs) sibs))
(module-test-external
(define test-pagetree `(pagetree-main foo bar (one (two three four))))
(check-equal? (other-siblings 'one test-pagetree) '(foo bar))
(check-equal? (other-siblings 'foo test-pagetree) '(bar one))
(check-equal? (other-siblings 'two test-pagetree) #f)
(check-equal? (other-siblings 'three test-pagetree) '(four))
(check-false (other-siblings #f test-pagetree))
(check-false (other-siblings 'invalid-key test-pagetree)))
;; private helper function.
;; only takes pt as input.
;; used by `pagetree?` predicate, so can't use `pagetree?` contract.

@ -1 +1 @@
1494629838
1494630905

@ -352,15 +352,29 @@ Find the child pagenodes of @racket[_p] within @racket[_pagetree]. Return @racke
[p (or/c #f pagenodeish?)]
[pagetree (or/c pagetree? pathish?) (current-pagetree)])
(or/c #f pagenode?)]
Find the sibling pagenodes of @racket[_p] within @racket[_pagetree]. The list will include @racket[_p] itself. But the function will still return @racket[#f] if @racket[_pagetree] is @racket[#f].
Find the sibling pagenodes of @racket[_p] within @racket[_pagetree]. The result includes @racket[_p] itself. But the function will still return @racket[#f] if @racket[_pagetree] is @racket[#f].
@examples[#:eval my-eval
(current-pagetree '(root (mama.html son.html daughter.html) uncle.html))
(current-pagetree '(root (mama.html son.html daughter.html)))
(siblings 'son.html)
(siblings 'daughter.html)
(siblings 'mama.html)
]
@defproc[
(other-siblings
[p (or/c #f pagenodeish?)]
[pagetree (or/c pagetree? pathish?) (current-pagetree)])
(or/c #f pagenode?)]
Like @racket[siblings], but the result does not include @racket[_p] itself.
@examples[#:eval my-eval
(current-pagetree '(root (mama.html son.html daughter.html)))
(other-siblings 'son.html)
(other-siblings 'daughter.html)
(other-siblings 'mama.html)
]
@deftogether[(

Loading…
Cancel
Save