Table of contents
TOC
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 8/18/2017
|
1 Contributor

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)

Syntax

// 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


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

Control.LazyExtensions Module (F#)

Lazy Computations (F#)

© 2019 Microsoft