quad-ends-with

main
Matthew Butterick 10 years ago
parent 3bc59a2460
commit 7bd08a679a

@ -1,8 +1,10 @@
#lang typed/racket/base
(require (for-syntax typed/racket/base racket/syntax racket/string))
(require/typed racket/list [empty? (All (A) ((Listof A) -> Boolean))])
(require/typed racket/list [empty? (All (A) ((Listof A) -> Boolean))]
[last ((Listof Any) . -> . Any)])
(require/typed sugar/list [trimf (All (A) ((Listof A) (A . -> . Boolean) -> (Listof A)))]
[filter-split (All (A) ((Listof A) (A . -> . Boolean) -> (Listof (Listof A))))])
(require/typed sugar/string [ends-with? (String String . -> . Boolean)])
(require sugar/debug)
(provide (all-defined-out))
@ -36,6 +38,7 @@
(define-type Quad quad)
(define-predicate Quad? Quad)
(define quad-attr-ref
(case-lambda
[([q : Quad] [key : QuadAttrKey])
@ -54,6 +57,18 @@
(define-type QuadAttrPair (Pairof QuadAttrKey QuadAttrValue))
(: quad-ends-with? (Quad String . -> . Boolean))
(define (quad-ends-with? q str)
(cond
[(not (empty? (quad-list q)))
(define last-item (last (quad-list q)))
(cond
[(string? last-item) (ends-with? last-item str)]
[(quad? last-item) (quad-ends-with? last-item str)]
[else #f])]
[else #f]))
(provide gather-common-attrs)
(: gather-common-attrs ((Listof Quad) . -> . (U False (Listof QuadAttrPair))))
(define (gather-common-attrs qs)

@ -41,8 +41,8 @@
(check-true (quad-has-attr? (box '(foo bar)) 'foo))
(check-equal? (quad-attr-set (box '(foo bar)) 'foo 'zam) (box '(foo zam)))
(check-equal? (quad-attr-set (box '()) 'foo 'zam) (box '(foo zam)))
(check-equal? (quad-attr-set* (box '()) 'foo 'zam 'bar 'boo) (box '(foo zam bar boo)))
(check-equal? (quad-attr-set (box #f) 'foo 'zam) (box '(foo zam)))
(check-equal? (quad-attr-set* (box #f) 'foo 'zam 'bar 'boo) (box '(foo zam bar boo)))
(check-equal? (quad-attr-set* (box '(foo bar)) 'foo 'zam 'bar 'boo) (box '(foo zam bar boo)))
(check-equal? (quad-attr-remove (box '(foo bar zim zam)) 'foo) (box '(zim zam)))
@ -51,4 +51,10 @@
(check-equal? (quad-attr-remove* (box #f) 'zim) (box))
(check-true (quad-ends-with? (box #f "foo") "foo"))
(check-false (quad-ends-with? (box #f "foo") "food"))
(check-false (quad-ends-with? (box #f (box #f "foo")) "food"))
(check-true (quad-ends-with? (box #f (box #f "foo")) "foo"))
(check-true (quad-ends-with? (box #f (box #f "foo")) "o"))
(check-true (quad-ends-with? (box #f (box #f (box #f (box #f (box #f "foo-"))))) "-"))

Loading…
Cancel
Save