take-while   scheme


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/libs/core/pattern-language.xtm

Implementation

;; return first N of list for which predicate is truthy
(define take-while
  (lambda (pred lst)
    (let loop ((ret '())
               (remaining lst))
      (cond
       ((null? remaining) (reverse ret))
       ((pred (car remaining)) (loop (cons (car remaining) ret) (cdr remaining)))
       (else (reverse ret))))))


Back to Index