Finds the first position of an item that matches a given predicate
within col. Returns nil if not found. Optionally provide a start
offset to search from.
(defn position
"Finds the first position of an item that matches a given predicate
within col. Returns nil if not found. Optionally provide a start
offset to search from."
([pred coll] (position pred coll 0))
([pred coll start]
(loop [coll (drop start coll), i start]
(when (seq coll)
(if (pred (first coll))
i
(recur (rest coll) (inc i))))))
{:tag Integer})
Comments top
No comments for position. Log in to add a comment.