Programming-Idioms

Implementation
Clojure

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating resource.

Please try to avoid dependencies to third-party libraries and frameworks.

Implementation edit is for fixing errors and enhancing with metadata.

Instead of changing the code of the snippet, consider creating another Clojure implementation.

Other implementations
let i = items.indexOf(x);
i := -1
for j, e := range items {
	if e == x {
		i = j
		break
	}
}
i = items.index(x) || -1
i := Items.IndexOf(x);
i = findloc(items, x)
if (i == 0) i = -1
i = items.index(x) if x in items else -1
import Data.Foldable (find)
import Data.Maybe (fromMaybe)
findIndex x items = fst <$> (find ((==x) . snd) . zip [0..]) items

i = fromMaybe -1 (findIndex x items)
let opt_i = items.iter().position(|y| *y == x);


let i = match opt_i {
   Some(index) => index as i32,
   None => -1
};
let i = items.iter().position(|y| *y == x).map_or(-1, |n| n as i32);
(defn find-index [x items]
  (or (->> items
         (map-indexed vector)
         (filter #(= x (peek %)))
         ffirst) -1))
i=items.indexOf(x)