https://github.com/testingrequired/lazy
Wrap an object to make its methods lazily evaluate.
https://github.com/testingrequired/lazy
Last synced: 11 months ago
JSON representation
Wrap an object to make its methods lazily evaluate.
- Host: GitHub
- URL: https://github.com/testingrequired/lazy
- Owner: testingrequired
- Created: 2019-12-06T03:33:55.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T02:25:45.000Z (about 3 years ago)
- Last Synced: 2025-01-22T06:28:15.554Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 607 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @testingrequired/lazy
Wrap an object to make its methods lazily evaluate.
## Installation
`$ npm i @testingrequired/lazy`
## Usage
```javascript
import assert from "assert";
import Lazy from "@testingrequired/lazy";
const lazyAssert = Lazy.of(assert);
lazyAssert.ok(false); // Does nothing
lazyAssert.ok(false)(); // Runs assertion
// This also works
const okFn = lazyAssert.ok(false); // Does nothing
okFn(); // Runs assertion
// Works with functions too
const hello = Lazy.fn(name => console.log(`Hello ${name}`));
const helloWorld = hello("World"); // Does nothing
const helloWorld(); // Hello World
```