Udostępnij za pośrednictwem


Lazy.Create<'T> Extension Method (F#)

Creates a lazy computation that evaluates to the result of the given function when forced.

Namespace/Module Path: Microsoft.FSharp.Control.LazyExtensions

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
type System.Lazy with
  member static Create : Lazy<'T>

// Usage:
lazy.Create (creator)

Parameters

  • creator
    Type: unit -> 'T

    The function to provide the value when needed.

Return Value

The created Lazy object.

Example

The following code illustrates the use of Create.

let lazyValue n = Lazy.Create (fun () ->
    let rec factorial n =
        match n with
        | 0 | 1 -> 1
        | n -> n * factorial (n - 1)
    factorial n)
let lazyVal = lazyValue 10
printfn "%d" (lazyVal.Force())

The output is the factorial of 10.

3628800

Platforms

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Version Information

F# Runtime

Supported in: 2.0

Silverlight

Supported in: 3

See Also

Reference

Control.LazyExtensions Module (F#)

Lazy<T>

Lazy Computations (F#)