Share via


List.sumBy<'T,^U> 関数 (F#)

リストの各要素に関数を適用することで生成された結果の合計を返します。

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

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

// Signature:
List.sumBy : ('T -> ^U) -> 'T list -> ^U (requires ^U with static member (+) and ^U with static member Zero)

// Usage:
List.sumBy projection list

パラメーター

  • projection
    型: 'T -> ^U

    リスト要素を合計される型に変換する関数。

  • list
    型: 'Tlist

    入力リスト。

戻り値

結果として得られた合計。

解説

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

使用例

List.sumList.sumBy、および List.average の使用方法を次のコード例に示します。

// Compute the sum of the first 10 integers by using List.sum.
let sum1 = List.sum [1 .. 10]

// Compute the sum of the squares of the elements of a list by using List.sumBy.
let sum2 = List.sumBy (fun elem -> elem*elem) [1 .. 10]

// Compute the average of the elements of a list by using List.average.
let avg1 = List.average [0.0; 1.0; 1.0; 2.0]

printfn "%f" avg1

出力

  

プラットフォーム

Windows 8、Windows 7、Windows Server 2012 で Windows Server 2008 R2

バージョン情報

F# コア ライブラリのバージョン

サポート: ポータブル 2.0、4.0

参照

関連項目

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

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