maximaster/lazy-scalar

Package provides lazy value objects which promise to return a specific scalar value

1.0.0 2025-04-17 10:30 UTC

This package is auto-updated.

Last update: 2025-04-17 10:43:55 UTC


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 qa before submitting a pull request;