(examples-for collect ("returns all matching items in a list" (collect (fn (x) (eq? (len x) 2)) (list "foo" "bar" "xx" "pp")) ("xx" "pp")) ("returns nil when nothing matches" (collect (fn (x) (eq? (len x) 20)) (list "foo" "bar" "xx" "pp")) nil) ;; kind of pointless ("returns list of nils if nil is the matching item" (collect no (list "foo" "bar" nil "pp" nil)) (nil nil)) ("returns item if it's an atom and matches" (collect (fn (x) (eq? (len x) 2)) "zz") "zz") ("preserves structure of improper list" (collect (fn (x) (eq? (len x) 2)) '("aa" "bbb" "cc" "ddd" . "ee")) ("aa" "cc" . "ee")) ("preserves structure of improper list: returns just the lastcdr" (collect (fn (x) (eq? (len x) 2)) '("aaa" "bbb" "ccc" "ddd" . "ee")) "ee") ("returns nil if it's an atom and doesn't match" (collect (fn (x) (eq? (len x) 20)) "zz") nil)) (examples-for compact ("removes all nil items in list" (compact (list 'a 'b nil 'c nil 'd nil nil)) (a b c d))) (examples-for +0 ("only adds non-nil items" (+nz 1 2 nil 3 nil 4 nil nil) 10)) (examples-for reject ("returns all non-matching items in a list" (reject (fn (x) (eq? (len x) 2)) (list "foo" "bar" "xx" "pp")) ("foo" "bar")) ("returns everything when nothing matches" (reject (fn (x) (eq? (len x) 20)) (list "foo" "bar" "xx" "pp")) ("foo" "bar" "xx" "pp")) ;; kind of pointless ("returns non-nils in list if nil is the matching item" (reject no (list "foo" "bar" nil "pp" nil)) ("foo" "bar" "pp")) ("returns item if it's an atom and doesn't match" (reject (fn (x) (eq? (len x) 3)) "zz") "zz") ("preserves structure of improper list" (reject (fn (x) (eq? (len x) 2)) '("aa" "bbb" "cc" "ddd" . "eee")) ("bbb" "ddd" . "eee")) ("ignores last-cons if matching" (reject (fn (x) (eq? (len x) 2)) '("aa" "bbb" "cc" "ddd" . "ee")) ("bbb" "ddd")) ("returns thing if it's an atom and doesn't match" (reject (fn (x) (eq? (len x) 20)) "zz") "zz"))