(examples-for detect ("returns first matching item in a list" (detect (fn (x) (eq? (len x) 2)) (list "foo" "bar" "xx" "pp")) "xx") ("returns nil when nothing matches" (detect (fn (x) (eq? (len x) 20)) (list "foo" "bar" "xx" "pp")) nil) ("returns t if nil is the matching item (warning: anomalous behaviour)" (detect no (list "foo" "bar" nil "pp")) t) ("finds first non-nil item using x1" (detect x1 (list nil nil "foo" "bar" nil "pp")) "foo") ("returns item if it's an atom and matches" (detect (fn (x) (eq? (len x) 2)) "zz") "zz") ("returns nil if it's an atom and doesn't match" (detect (fn (x) (eq? (len x) 20)) "zz") nil) ("empty list" (detect present? nil) nil) ("present? for list of empty things" (detect present? (list "" nil {} ())) nil) ("present? for mostly empty things" (detect present? (list "" nil 42 {} ())) 42) ("nil for nil" (detect nil nil) nil) ("true for nil in list containing nil" (detect nil '(1 2 nil 3 4)) t) ("nil for nil in list not containing nil" (detect nil '(1 2 3 4 5)) nil) ("true for 42 in list containing 42" (detect 42 '(1 2 nil 3 42 4)) 42) ("nil for 42 in list not containing 42" (detect 42 '(1 2 nil 3 (a b c) 4)) nil))