A small wrapper class for lazy computed values.
Install with npm
or yarn
:
$ npm i git+https://github.com/felix-kaestner/lazy
$ yarn add git+https://github.com/felix-kaestner/lazy
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
})
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.