PHP code example of linepogl / impartial-pipes

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

    

linepogl / impartial-pipes example snippets


// PHP 8.5
$array
|> static fn ($in) => array_map(static fn (int $x) => $x * $x), $in)
|> static fn ($in) => array_filter($in, static fn (int $x) => $x % 2 === 1)

// PHP > 8.5, if accepted
$array
|> array_map(static fn (int $x) => $x * $x), ...)
|> array_filter(..., static fn (int $x) => $x % 2 === 1)

// PHP 8.5, with Impartial Pipes
$iterable
|> p_map(static fn (int $x) => $x * $x)
|> p_filter(static fn (int $x) => $x % 2 === 1)

// PHP 8.4, with Impartial Pipes
p_filter(static fn (int $x) => $x % 2 === 1)(
  p_map(static fn (int $x) => $x * $x)(
    $iterable
  )
)

// PHP 8.4, with Impartial Pipes
pipe($iterable)
->to(p_filter(static fn (int $x) => $x % 2 === 1))
->to(p_map(static fn (int $x) => $x * $x))