Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if an element is within a sequence

Tags:

f#

how to check if an element is contained within a sequence? I expected some Seq.contains, but i could not find it. Thanks

EDIT: Or, for an easier task, how to make the diff between two sequences? Like, getting all the elements within a list that doesn not belong to another (or that do)?

like image 429
pistacchio Avatar asked Jul 21 '09 08:07

pistacchio


2 Answers

Little bit simpler:

let contains x = Seq.exists ((=) x)
like image 191
The_Ghost Avatar answered Oct 12 '22 09:10

The_Ghost


Seq.exists

let testseq = seq [ 1; 2; 3; 4 ]
let equalsTwo n = (n = 2)
let containsTwo = Seq.exists equalsTwo testseq
like image 21
Benjol Avatar answered Oct 12 '22 09:10

Benjol