次の方法で共有


Seq.collect<'T,'Collection,'U> 関数 (F#)

更新 : 2010 年 8 月

指定された関数をシーケンスの各要素に適用し、すべての結果を連結します。

名前空間/モジュール パス: Microsoft.FSharp.Collections.Seq

アセンブリ: FSharp.Core (FSharp.Core.dll 内)

// Signature:
Seq.collect : ('T -> 'Collection) -> seq<'T> -> seq<'U> (requires 'Collection :> seq<'U>)

// Usage:
Seq.collect mapping source

パラメーター

  • mapping
    型: 'T -> 'Collection

    入力シーケンスの各要素を、連結されるシーケンスに変換する関数。

  • source
    型: seq<'T>

    入力シーケンス。

例外

例外

状態

ArgumentNullException

入力シーケンスが null の場合にスローされます。

戻り値

結果のシーケンス。

解説

シーケンスは遅延評価されます。 このため、列挙されるまで効果は遅延します。

この関数は、コンパイルされたアセンブリでは Collect という名前です。 F# 以外の言語から、またはリフレクションを使用してこの関数にアクセスする場合は、この名前を使用します。

使用例

Seq.collect を使用したコードの例を次に示します。

let addNegations seq1 =
   Seq.collect (fun x -> seq { yield x; yield -x }) seq1
   |> Seq.sort
addNegations [ 1 .. 4 ] |> Seq.iter (fun elem -> printf "%d " elem)
printfn ""
addNegations [| 0; -4; 2; -12 |] |> Seq.iter (fun elem -> printf "%d " elem)

出力

  

プラットフォーム

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

参照

その他の技術情報

Collections.Seq モジュール (F#)

Microsoft.FSharp.Collections 名前空間 (F#)

履歴の変更

日付

履歴

理由

2010 年 8 月

コード例を追加。

情報の拡充