Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #lang racket
- (require rackunit)
- (define (grouping values pred [acc '()])
- (if (empty? values)
- acc
- (let-values ([(taken rest) (splitf-at values pred)])
- (grouping
- (dropf rest (negate pred))
- pred
- (append acc (list taken))))))
- (check-equal? '()
- (grouping '() number?))
- (check-equal? '((1 2 3))
- (grouping '(1 2 3) number?))
- (check-equal? '((1 2 3) (4 5 6))
- (grouping '(1 2 3 null 4 5 6) number?))
- (check-equal? '(("a" "b" "c") ("d" "e" "f"))
- (grouping (list
- "a" "b" "c"
- ""
- "d" "e" "f") non-empty-string?))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement