Lazy.Create<'T> 扩展方法 (F#)

创建一个在强制执行时的计算结果为给定函数的结果的延迟计算。

命名空间/模块路径: Microsoft.FSharp.Control.LazyExtensions

程序集:FSharp.Core(在 FSharp.Core.dll 中)

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

// Usage:
lazy.Create (creator)

参数

  • creator
    类型:unit -> 'T

    用于在需要时提供值的函数。

返回值

创建的 Lazy 对象。

示例

下面的代码阐释了 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())

输出为 10 的阶乘。

  

平台

Windows 8,Windows 7,Windows server 2012中,Windows server 2008 R2

版本信息

F#核心库版本

受以下版本支持:2.0

请参见

参考

Control.LazyExtensions 模块 (F#)

Lazy<T>

延迟计算 (F#)