Logo

Programming-Idioms

History of Idiom 222 > diff from v16 to v17

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

Version 16

2021-01-14, 22:13:16

Version 17

2021-01-14, 22:15:09

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]
  (reduce-kv
    #(if (= x %3) (reduced %2) %1) -1 c))
Comments bubble
clojure already provides some cool iteration functions to be used with the concept of reduction