PasteRack.org
Paste # 54926
2020-07-08 19:33:44

Fork as a new paste.

Paste viewed 231 times.


Embed:

`split-by'

  1. #lang racket/base
  2. (define (split-by f lst (pred? =))
  3.   (reverse
  4.    (let loop ((lst lst) (acc '()))
  5.      (cond
  6.        ((null? lst)
  7.         acc)
  8.        ((or (null? acc)
  9.             (not (pred? (f (car lst))
  10.                         (f (caar acc)))))
  11.         (loop (cdr lst) (cons (list (car lst)) acc)))
  12.        (else
  13.         (loop (cdr lst) (cons (cons (car lst) (car acc)) (cdr acc))))))))

=>