PHP code example of maximaster / lazy-scalar

1. Go to this page and download the library: Download maximaster/lazy-scalar library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

maximaster / lazy-scalar example snippets




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");