Aracılığıyla paylaş


Option.fold<'T,'State> İşlevi (F#)

Eşdeğeri değerlendiren List.fold için bir seçenek.

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

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

// Signature:
fold : ('State -> 'T -> 'State) -> 'State -> 'T option -> 'State

// Usage:
fold folder state option

Parametreler

  • folder
    Türü:'State -> 'T -> 'State

    Bir seçenekten değer verildiğinde durum verilerini güncelleştirmek için bir işlev.

  • state
    Türü:'State

    Başlangıç durumu.

  • option
    Type: 'Toption

    Giriş seçeneği.

Dönüş Değeri

Seçenek ise özgün durumuna None, aksi takdirde klasörü ve seçenek değeri ile güncel durumu döndürür.

Notlar

İfade fold f s inp veren match inp with None -> s | Some x -> f s x.

Bu işlev adlı Fold 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.fold.

let consOption list opt =
    Option.fold (fun state value -> value :: state) list opt
printfn "%A" <| consOption [1 .. 10] None
printfn "%A" <| consOption [1 .. 10] (Some(0))

// Read input from the console, and if the input parses as
// an integer, cons to the list.
let readNumber () =
    let line = System.Console.ReadLine()
    let (success, value) = System.Int32.TryParse(line)
    if success then Some(value) else None
let mutable list1 = []
let mutable count = 0
while count < 5 do
    printfn "Enter a number: "
    list1 <- consOption list1 (readNumber())
    printfn "New list: %A" <| list1
    count <- count + 1

Çı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#)