anchor.diff:       (keep 'x ((x 1) (y 2) (x 3)) :key #'car)
        => '((x 1) (x 3))"
     (declare (ignore from-end key))
  -  (let ((args (remove-from-plist args :test :count)))
  -    (cond ((null count)
  -           (apply #'remove item seq :test-not test args))
  -          ((< count 1)
  -           (make-sequence-like seq 0))
  -          (t (fbind ((test (curry test item)))
  -               (declare (dynamic-extent #'test))
  -               (apply #'filter #'test seq :count count args))))))
  +  (let ((args (remove-from-plist args :test)))
  +    (if (null count)
  +        (apply #'remove item seq :test-not test args)
  +        (fbind ((test (curry test item)))
  +          (declare (dynamic-extent #'test))
  +          (apply #'filter #'test seq :count count args)))))
   
   (assert (equal '((a 1) (a 2))
                  (keep 'a '((a 1) (b) (c) (a 2) (a 3) (b) (c) (a 4) (a 5))
  
positive.code:     (assort '(1 2 3) :key #'evenp) => ((1 3) (2))
      (partition #'evenp '(1 2 3)) => (2), (1 3)"
    (fbind ((test (compose pred key)))
      (seq-dispatch seq
        (progn
          (setf seq (nthcdr start seq))
          (let ((pass (queue))
                (fail (queue)))
            (flet ((pass/fail (item)
                     (if (test item)
                         (enq item pass)
                         (enq item fail))))
              (declare (dynamic-extent #'pass/fail))
              (if (null end)
                  (dolist (item seq)
                    (pass/fail item))
                  (loop for i from 0 below (- end start)
                        for item in seq
                        do (pass/fail item))))
            (values (qlist pass) (qlist fail))))
        ;; Vector.
        (progn
          (let* ((pass (make-array 0
                                   :element-type (array-element-type seq)
                                   :adjustable t
                                   :fill-pointer 0))
                 (fail (copy-array pass)))
            (loop for i from start below (or end (length seq))
                  for item = (aref seq i)
                  do (if (test item)
                         (vector-push-extend item pass)
                         (vector-push-extend item fail)))
            (values pass fail)))
        ;; Generic sequence.
        (values (remove-if pred seq :key key)
                (remove-if-not pred seq :key key)))))
  
  (defun partitions (preds seq &key (start 0) end (key #'identity))
    "Generalized version of PARTITION.
  
negative.code:   (replace seq value :start1 start :end1 end)
    value)
  
  (defun filter/counted (pred seq &rest args
                         &key count from-end (start 0) end
                              (key #'identity))
    "Helper for FILTER."
    (fbind (pred key)
      (declare (dynamic-extent #'pred #'key))
      (cond
        ;; Simple cases.
        ((= count 0) (make-sequence-like seq 0))
        ((> count (length seq)) (apply #'filter pred seq :count nil args))
        (t (let ((ret (make-bucket seq)))
             (block nil
               (map-subseq (lambda (item)
                             (when (pred (key item))
                               (bucket-push seq item ret)
                               (when (zerop (decf count))
                                 (return))))
                           seq start end from-end))
             (let ((seq2 (bucket-seq seq ret)))
               (if from-end (nreverse seq2) seq2)))))))
  
  (defun filter (pred seq &rest args &key count &allow-other-keys)
    "Almost, but not quite, an alias for `remove-if-not'.
  