💾 Archived View for idiomdrottning.org › chunk-by captured on 2024-12-17 at 12:08:03. Gemini links have been rewritten to link to archived content
-=-=-=-=-=-=-
Takes a list and splits it in order into smaller lists such that each list contains one pred. If there are no pred, that’s fine, DTRT silently i.e. make a one-element list containing the whole list.
(define (vowel? l) ((as-list (c member l)) "aeiou")) (define (chunk-by pred lis) (list lis)) (define (chunk-by pred lis) (receive (hd tl) (split-at lis (add1 (require number? (list-index pred lis)))) (cons hd (chunk-by pred (require (c any pred) tl))))) (chunk-by vowel? (string->list "somejunk")) ⇒ ((#\s #\o) (#\m #\e) (#\j #\u #\n #\k))