position

swank.util

  • (position pred coll)
  • (position pred coll start)
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.

0 Examples top

Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source swank/util.clj:18 top

(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})
Vars in swank.util/position: defn first inc loop rest seq when
Used in 0 other vars

Comments top

No comments for position. Log in to add a comment.