PHP code example of xphere / lazzzy

1. Go to this page and download the library: Download xphere/lazzzy 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/ */

    

xphere / lazzzy example snippets


use Lazzzy\Container;

$container = Container::from(range(0, 1000));

use Lazzzy\Container;

$expected = ['a' => 0, 'b' => 1, 'c' => 2];
$container = Container::from($expected);

$values = $container->toAssoc();

$this->assertEquals($expected, $values);

use Lazzzy\Container;

$expected = [0, 1, 2];
$values = ['a' => 0, 'b' => 1, 'c' => 2];
$container = Container::from($expected);

$values = $container->toAssoc();

$this->assertEquals($expected, $values);

use Lazzzy\Container;

$echo = function ($item) { echo $item, ', '; };
$container = Container::from(range(0, 5));

$container->each($echo);

/// Outputs "0, 1, 2, 3, " and returns nothing

use Lazzzy\Container;

$expected = [0, 2, 4, 6];
$double = function ($item) { return $item * 2; };
$container = Container::from(range(0, 3))
    ->map($double)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);

use Lazzzy\Container;

$expected = [1, 3];
$odd = function ($item) { return $item % 2 === 1; };
$container = Container::from(range(0, 3))
    ->filter($odd)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);

use Lazzzy\Container;

$expected = [0, 1];
$container = Container::from(range(0, 3))
    ->take(2)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);

use Lazzzy\Container;

$expected = [0, 1];
$notEqualsTwo = function ($item) { return $item !== 2; };
$container = Container::from(range(0, 3))
    ->takeWhile($notEqualsTwo)
;

$actual = $container->toArray();

$this->assertSame($expected, $actual);