Logo

Programming-Idioms

History of Idiom 222 > diff from v24 to v25

Edit summary for version 25 by Naxels:
New Elixir implementation by user [Naxels]

Version 24

2021-08-08, 13:47:41

Version 25

2021-08-08, 13:51:40

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
Enum.find_value(items, -1, fn val -> if val == x, do: x end)
Doc URL
https://hexdocs.pm/elixir/Enum.html#find_value/3-examples