Skip to content

felix-kaestner/lazy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lazy

A small wrapper class for lazy computed values.

Codecov Issues Stars License Twitter

Install

Install with npm or yarn:

$ npm i git+https://github.com/felix-kaestner/lazy
$ yarn add git+https://github.com/felix-kaestner/lazy

Usage

Generate a lazy computed value which is memoized once it is computed.

import Lazy from '@felix-kaestner/lazy'

const lazy = new Lazy(() => {
    // Do some computation which should be run lazily when needed and then memoized
    // ...
    return 42
})


// Retrieve the value from the instance
// using the `value` property
console.log(lazy.value)

TypeScript

The Lazy class accepts a generic type parameter.

import Lazy from '@felix-kaestner/lazy'

const lazy = new Lazy<number>(() => {
    // ...
    return 42
})

Contribute

All contributions in any form are welcome! 🙌
Just use the Issue and Pull Request templates and I will be happy to review your suggestions. 👍


Released under the MIT License.