List.tryFind<'T> 関数 (F#)

指定した関数が true. を返す最初の要素を返します。そのような要素が存在しない場合は、None を返します。

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

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

// Signature:
List.tryFind : ('T -> bool) -> 'T list -> 'T option

// Usage:
List.tryFind predicate list

パラメーター

  • predicate
    型: 'T ->bool

    入力要素をテストする関数。

  • list
    型: 'Tlist

    入力リスト。

戻り値

述語が true を返す最初の要素、またはすべての要素が false と評価された場合は None。

解説

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

使用例

List.tryFindList.tryFindIndex の使用方法を次のコード例に示します。

let list1d = [1; 3; 7; 9; 11; 13; 15; 19; 22; 29; 36]
let isEven x = x % 2 = 0
match List.tryFind isEven list1d with
| Some value -> printfn "The first even value is %d." value
| None -> printfn "There is no even value in the list."

match List.tryFindIndex isEven list1d with
| Some value -> printfn "The first even value is at position %d." value
| None -> printfn "There is no even value in the list."

出力

  
  

プラットフォーム

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

バージョン情報

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

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

参照

関連項目

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

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