Aracılığıyla paylaş


Option.count<'T> İşlevi (F#)

Eşdeğeri değerlendiren Set.count için bir seçenek.

Ad alanı/modül yolu: Microsoft.FSharp.Core.Option

Derleme: FSharp.Core (FSharp.Core.dll),

// Signature:
count : 'T option -> int

// Usage:
count option

Parametreler

  • option
    Type: 'Toption

    Giriş seçeneği.

Dönüş Değeri

Seçenek ise sıfır None, aksi takdirde bir tane.

Notlar

İfade count inp veren match inp with None -> 0 | Some _ -> 1.

Bu işlev adlı Count kodları derlenmiş derlemeleri.İşlev yansıtma veya F# dışındaki bir dilde erişiyorsanız, bu adı kullanın.

Örnek

Aşağıdaki kod kullanımları gösterilmektedir Option.count.

let opt1 = Some("test")
let opt2 = None
printfn "%A %A" (Option.count opt1) (Option.count opt2)

// Use Option.count to count the number of Some values in
// an array of options.
let getCount (array1 : int option array) =
    Array.fold (fun state elem -> state + Option.count elem) 0 array1
let testArray1 = [| Some(10); None; Some(1); None; None; Some(56) |]
let testArray2 = [| for i in 1 .. 10 do if i % 2 = 0 then yield Some(i) else yield None |]
printfn "%d" <| getCount testArray1
printfn "%d" <| getCount testArray2

Çıktı

  

Platformlar

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Sürüm Bilgisi

F# Çekirdek Kitaplığı sürümleri

Desteklenen: 2.0, 4.0, Portable

Ayrıca bkz.

Başvuru

Core.Option Modülü (F#)

Microsoft.FSharp.Core İsim Uzayı (F#)