Created
September 12, 2015 00:10
-
-
Save lispm/1e0fbd194e34c0693441 to your computer and use it in GitHub Desktop.
simpler CL split-with implementation than in dash.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun split-with (pred list) | |
"splits the LIST at the first NIL result of PRED" | |
(values (loop while (and (not (null list)) | |
(funcall pred (first list))) | |
collect (pop list)) | |
list)) | |
(defun map-while (predicate function list) | |
(loop with e | |
while (not (null list)) | |
do (setf e (pop list)) | |
while (funcall predicate e) | |
collect (funcall function e))) | |
(defun map-while (predicate function list &aux e r rt) | |
(do () | |
((or (null list) | |
(not (funcall predicate (first list)))) | |
r) | |
(setf e (funcall function (pop list))) | |
(if r | |
(setf (rest rt) (list e) | |
rt (rest rt)) | |
(setf r (list e) | |
rt r)))) | |
(defun take-while (predicate list) | |
(values (map-while predicate | |
(lambda (e) | |
(pop list) | |
e) | |
list) | |
list)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment