Seq.exists2<'T1,'T2> 函式 (F#)
更新:2010 年 8 月
測試輸入序列之所有對應的成對項目是否都滿足指定的述詞。
命名空間/模組路徑: Microsoft.FSharp.Collections.Seq
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
Seq.exists2 : ('T1 -> 'T2 -> bool) -> seq<'T1> -> seq<'T2> -> bool
// Usage:
Seq.exists2 predicate source1 source2
參數
predicate
Type: 'T1 -> 'T2 -> bool測試輸入序列中每對項目的函式。
source1
型別:seq<'T1>第一個輸入序列。
source2
型別:seq<'T2>第二個輸入序列。
例外狀況
例外狀況 |
條件 |
---|---|
會在兩個輸入序列的其中一個為 null 時擲回。 |
傳回值
這個述詞套用至兩個序列中的相符項目,數目最多可達長度較短之集合的長度。 如果任何應用程式會傳回 true整體的結果則會是 true並沒有進一步的項目會測試 否則,傳回 false。
備註
如果一個序列較另一個短,則較長序列中多的項目都會遭忽略。
這個函式是名為 Exists2中 已編譯的組件。 如果從一個語言,F # 以外,或透過反映存取函式使用這個名稱。
範例
在下列程式碼範例中,示範了如何使用 Seq.exists2。
// Use Seq.exists2 to compare elements in two sequences.
// isEqualElement returns true if any elements at the same position in two supplied
// sequences match.
let isEqualElement seq1 seq2 = Seq.exists2 (fun elem1 elem2 -> elem1 = elem2) seq1 seq2
let seq1to5 = seq { 1 .. 5 }
let seq5to1 = seq { 5 .. -1 .. 1 }
if (isEqualElement seq1to5 seq5to1) then
printfn "Sequences %A and %A have at least one equal element at the same position." seq1to5 seq5to1
else
printfn "Sequences %A and %A do not have any equal elements that are at the same position." seq1to5 seq5to1
輸出
平台
Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2
版本資訊
F# 執行階段
支援版本:2.0、4.0
Silverlight
支援版本:3
請參閱
參考
Microsoft.FSharp.Collections 命名空間 (F#)
變更記錄
日期 |
History |
原因 |
---|---|---|
2010 年 8 月 |
加入程式碼範例。 |
資訊加強。 |