Haskell has "elem" predicate to tell like:
Prelude> 5 `elem` [2,4..10]
False
In F#, how to conveniently tell whether a value is in a list, or array, or seq or map, or dictionary?
Haskell has "elem" predicate to tell like:
Prelude> 5 `elem` [2,4..10]
False
In F#, how to conveniently tell whether a value is in a list, or array, or seq or map, or dictionary?
In F# it is
List.contains <element> <list>
Example:
List.contains 5 [2..2..10]
-->
val it : bool = false
contains
is also defined for the other container types.
You can use:
List.exists ((=) 5) [1..5]
Or as suggested in the other answer, directly List.contains
if you have the latest F# version.
The same functions are available for Seq
.