Essentially, I want a function that works like this:
user=> (pos 'c '(a b c d e f g) =)
2
user=> (pos 'z '(a b c d e f g) =)
nil
And I came up with this:
(defn pos
"Gets position of first object in a sequence that satisfies match"
[object sequence match]
(loop [aseq sequence position 0]
(cond (match object (first aseq)) position
(empty? aseq) nil
:else (recur (rest aseq) (inc position)))))
So my question is, is there some built-in function that would allow us to do this, or would there be a better, more functional/Clojure-ish way to write the pos
function?