maximaster / lazy-scalar
Package provides lazy value objects which promise to return a specific scalar value
Installs: 12
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/maximaster/lazy-scalar
Requires
- php: >=8.1
Requires (Dev)
- kahlan/kahlan: ^5.2
- phpstan/phpstan: ^1.10
- symplify/easy-coding-standard: ^12.5
README
The package provides lazy value objects which promise to return a specific scalar value.
Supported scalars:
- int (LazyInt);
- float (LazyFloat);
- bool (LazyBool);
- string (LazyString);
Installation
composer require maximaster/lazy-scalar
Usage Example
<?php
use Maximaster\LazyScalar\LazyScalar\LazyInt;
use Maximaster\LazyScalar\LazyScalar\LazyBool;
use Maximaster\LazyScalar\LazyScalar\LazyFloat;
use Maximaster\LazyScalar\LazyScalar\LazyString;
$lazyInt = new LazyInt(fn() => 42);
// Value not computed yet.
echo $lazyInt->isComputed(); // false
// Now it's computed.
echo $lazyInt->getValue(); // 42
echo $lazyInt->isComputed(); // true
// Will return cached value.
echo $lazyInt->getValue(); // 42
// Other types work similarly.
$lazyBool = new LazyBool(fn() => true);
$lazyFloat = new LazyFloat(fn() => 3.14);
$lazyString = new LazyString(fn() => "Hello");
Contributing
composer qabefore submitting a pull request;