Logo

Programming-Idioms

History of Idiom 222 > diff from v22 to v23

Edit summary for version 23 by Naxels:
[Clojure] Putting the -1)) on the new line, enhances the readability by users of the (or path

Version 22

2021-03-26, 18:36:51

Version 23

2021-08-08, 13:32:02

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.

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