PHP code example of rodnaph / singer

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

    

rodnaph / singer example snippets


$values = array(1, 2, 3);
$evenValues = array_filter($values, $even);
$incdValues = array_map($inc, $evenValues);

$result = array_map(
	$inc,
    array_filter(
        $values,
        $even
    )
);

use Singer\Thread as T;

// standard version

$values = array(1, 2, 3);
$evenValues = array_filter($values, $even);
$incdValues = array_map($inc, $evenValues);

// singer version

T::singer($values)
    ->filter($even)
    ->map($inc)
    ->value();

function array_last($array)
{
    return $array[count($array) - 1];
}

T::create(array(1,2,3))
    ->threadLast()
    ->array_last()
    ->threadFirst()
    ->range(10)
    ->value(); // array(3,4,5,6,7,8,9,10);

T::create($x)
    ->threadNth(3)
    ->someFunc($one, $two)
    ->value();

T::create('foo bar baz')
    ->threadFirst()
    ->inNamespace('String\Utils')
    ->sentenceCase()
    ->inNamespace('Word\Utils')
    ->countWords()
    ->value(); // 3

T::create('foo')
    ->onClass('Some\Static\Class')
    ->the_method() // Class::the_method()
    ->onObject($foo)
    ->bar() // $foo->bar()
    ->value();

T::create($initial);

T::singer($initial);

T::singer(array(1,2,3))
    ->map($inc)
    ->filter($even)
    ->reduce($toTotal, 0)
    ->value();

T::create(array(1, 2, 3))
    ->map($inc)
    ->debug() // will print_r(array(2, 3, 4)) and exit
    ->filter($odd)
    ->value();

T::create(array(1, 2, 3))
    ->map($inc)
    ->debug(function($context) { ... });