Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/felix-kaestner/lazy

A small wrapper class for lazy computed values
https://github.com/felix-kaestner/lazy

typescript

Last synced: about 5 hours ago
JSON representation

A small wrapper class for lazy computed values

Awesome Lists containing this project

README

        

# 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.

```JavaScript
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.

```TypeScript
import Lazy from '@felix-kaestner/lazy'

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

## Contribute

All contributions in any form are welcome! 🙌
Just use the [Issue](.github/ISSUE_TEMPLATE) and [Pull Request](.github/PULL_REQUEST_TEMPLATE) templates and
I will be happy to review your suggestions. 👍

---

Released under the [MIT License](LICENSE).