Skip to main content

lazy

Callable

  • lazy<T>(getValue: () => T): () => T

  • Returns the result of getValue, that will be called once. Useful for expensive computation

    @example
    const expensiveRead = lazy(() => fs.readDirSync('my/dir'));
    // fs.readDirSync not called
    console.log(
    expensiveRead() // <- fs.readDirSync called, return value is put in cache
    );
    console.log(
    expensiveRead() // <- fs.readDirSync not called, return value from cache
    );

    Type parameters

    • T