Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust
list.contains(&x);

See also more general alternative implementations.
list.iter().any(|v| v == &x)

This works for most iterable types.
list.binary_search(&x).is_ok()

The list must be sorted!
(&list).into_iter().any(|v| v == &x)

This is the the truly general version, but it isn't the most idiomatic.
with Ada.Containers.Vectors;
Result := List.Contains (X);

New implementation...