Check if an element is within a sequence

前端 未结 5 710
野性不改
野性不改 2021-01-07 23:51

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 tas

5条回答
  •  星月不相逢
    2021-01-08 00:51

    (Another question, another answer.)

    This works, but I don't think that it's the most idomatic way to do it - (you'll need to wait until the US wakes up to find out):

    let s1 = seq [ 1; 2; 3; 4 ]
    let s2 = seq [ 3; 4; 5; 6 ]
    
    seq {
        for a in s1 do
            if not (Seq.exists (fun n -> n = a) s2) then
                yield a
            }
    

提交回复
热议问题