Compartilhar via


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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0

See Also

Reference

Control.LazyExtensions Module (F#)

Lazy

Lazy Computations (F#)