Logo

Programming-Idioms

History of Idiom 222 > diff from v15 to v16

Edit summary for version 16 by yvendruscolo:
New Clojure implementation by user [yvendruscolo]

Version 15

2020-07-18, 20:49:05

Version 16

2021-01-14, 22:13:16

Idiom #222 Find first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Idiom #222 Find first index of an element in list

Set i to the first index in list items at which the element x can be found, or -1 if items does not contain x.

Extra Keywords
position
Extra Keywords
position
Code
(defn find-index [x c]
  (or (->> c
         (map-indexed vector)
         (filter #(= x (peek %)))
         ffirst) -1))