Seq.forall2<'T1,'T2> 函式 (F#)
測試從兩個序列中取出的所有成對項目是否都滿足指定的述詞。如果一個序列較另一個短,則較長序列中多的項目都會遭忽略。
**命名空間/模組路徑:**Microsoft.FSharp.Collections.Seq
組件:FSharp.Core (在 FSharp.Core.dll 中)
// Signature:
Seq.forall2 : ('T1 -> 'T2 -> bool) -> seq<'T1> -> seq<'T2> -> bool
// Usage:
Seq.forall2 predicate source1 source2
參數
predicate
型別:'T1 -> 'T2 ->bool函式,測試輸入序列中的成對項目。
source1
型別:seq<'T1>第一個輸入序列。
source2
型別:seq<'T2>第二個輸入序列。
例外狀況
例外狀況 |
條件 |
---|---|
當其中一個輸入序列為 null 時擲回。 |
傳回值
如果序列中的所有項目組都滿足指定的述詞,則為 true。否則會傳回 false。
備註
這個函式在已編譯的組件中名為 ForAll2。如果您是透過 F# 以外的語言,或是透過反映來存取函式,請使用這個名稱。
範例
下列程式碼示範 Seq.forall2 的用法。
// This function can be used on any sequence, so the same function
// works with both lists and arrays.
let allEqual coll = Seq.forall2 (fun elem1 elem2 -> elem1 = elem2) coll
printfn "%A" (allEqual [| 1; 2 |] [| 1; 2 |])
printfn "%A" (allEqual [ 1; 2 ] [ 2; 1 ])
Output
平台
Windows 8 中, Windows 7, Windows Server 2012 上, Windows Server 2008 R2
版本資訊
F# 核心程式庫版本
支援版本:2.0, 4.0,可攜式執行檔 (PE)。