Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
- Ada
- C
- Caml
- Clojure
- Clojure
- C++
- C++
- C#
- D
- Dart
- Elixir
- Elixir
- Erlang
- Erlang
- Erlang
- Fortran
- Fortran
- Go
- Go
- Groovy
- Haskell
- Haskell
- JS
- JS
- Java
- Java
- Java
- Java
- Kotlin
- Kotlin
- Lisp
- Lisp
- Lua
- Obj-C
- PHP
- Pascal
- Pascal
- Pascal
- Perl
- Perl
- Prolog
- Python
- Ruby
- Rust
- Rust
- Rust
- Rust
- Scala
- Scheme
- Scheme
- Smalltalk
- VB
List.mem x list
(some #{x} list)
(some (partial = x) list)
x in list
Enum.member?(list, x)
member(_, []) -> false;
member(Value, [H|_]) where Value =:= H -> true;
member(Value, [_|T]) -> member(Value, T).
member(_, []) -> false;
member(Value, [H|T]) ->
case H of
Value -> true;
_ -> member(T)
end.
lists:member(X, List).
if (any(x == list)) ...
"x == list" returns an array of booleans. any() is true if any element of the argument array is true.
if (findloc (list, x, 1) != 0) then
list.contains(x)
find _ [] = False
find n (x:xs)
| x == n = True
| otherwise = find n xs
return list.indexOf(x) !== -1;
Array.prototype.includes() is preferred but if you are supporting browsers that are 5+ years old, for example IE11, and you are not using a transpiler, then the old syntax with indexOf is generally well-understood.
return list.includes(x);
ES7 (Works on strings from ES6)
boolean <T> contains(T[] list, T x){
if( x==null){
for(T y:list)
if( y==null )
return true;
}else{
for(T y:list)
if( x.equals(y) )
return true;
}
return false;
}
This applies to an array of any non-primitive type T
boolean contains(int[] list, int x){
for(int y:list)
if( y==x )
return true;
return false;
}
This applies to an array of primitive values, e.g. int
(find x list :test #'equal)
Returns the value if it is in the list, otherwise returns nil.
(member x list)
[list containsObject:x];
Objects are considered equal if `isEqual:` returns YES.
in_array($x, $list, true);
in_array returns true if value exists in array $list
Last argument should be set to true. Otherwise unexpected behavior is very likely to happen, for details see php manual.
Last argument should be set to true. Otherwise unexpected behavior is very likely to happen, for details see php manual.
result := false;
for e in list do
if e=x then
begin
result := true;
break;
end
p := list;
while (p <> nil) and (p^.key = x) do p := p^.next;
found := p.key = x
print "Found 'foo'\n" if grep {$_ eq $x} @list;
The inside of the curly braces for a hash(map) reference is automatically stringified.
x in list
This indirectly calls list._contains__() and returns True or False
list.include? x
list.contains(x)
(define (contains list x)
(cond [(null? list) #f]
[(equal? (car list) x) #t]
[else (contains (cdr list) x)]))
This is a custom implementation, use it if no built-in predicate is available in your Scheme environment.
list includes: x.
List.Contains(x)