ruricolist / serapeum

Utilities beyond Alexandria
MIT License
415 stars 41 forks source link

Util suggestion: drop-until, take-until #158

Closed bo-tato closed 10 months ago

bo-tato commented 11 months ago

I use them reasonably often, and I'm not the only one, I saw they're added here. maybe it makes sense to add to serapeum? Most simple implementation would be as there:

(defun drop-until (pred seq)
  (drop-while (complement pred) seq))

Personally I like to have it take a predicate or a value:

(defun drop-until (pred-or-val seq)
  (let ((pred (if (functionp pred-or-val)
                  pred-or-val
                  (lambda (x) (equal x pred-or-val)))))
    (drop-while (complement pred) seq)))

so then ie instead of writing (drop-until (lambda (n) (equal n 7)) (range 10)) I can just write (drop-until 7 (range 10))

ruricolist commented 10 months ago

I've added these. For the case of drop-until with a constant, I think the best thing would be to use eqls, which returns a function to test for equality: (drop-until (eqls 7) (range 10)).