(defun iterate (end-p cur-fun step-fun start function) (labels ((next (object) (unless (funcall end-p object) (let* ((cur (funcall cur-fun object)) (next (funcall step-fun object)) (result (funcall function cur))) (if (typep result 'promise) (then result (lambda (v) (declare (ignore v)) (funcall #'next next))) (then (pend :success next) #'next)))))) (then (pend :success start) #'next))) (defun each (sequence function) (etypecase sequence (null (pend :success NIL)) (list (iterate #'null #'car #'rest sequence function)) (vector (let ((length (length sequence))) (iterate (lambda (i) (<= length i)) (lambda (i) (aref sequence i)) #'1+ 0 function)))))