PHP code example of phunkie / console

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

    

phunkie / console example snippets


phunkie > 1 + 2
$var0: Int = 3

phunkie > ImmList(1, 2, 3, 4, 5)->map(fn($x) => $x * 2)
$var1: ImmList = List(2, 4, 6, 8, 10)

phunkie > Some(42)->map(fn($x) => $x * 2)
$var2: Option = Some(84)

phunkie > Some(42)->getOrElse(0)
$var0: Int = 42

phunkie > None()->getOrElse(0)
$var1: Int = 0

phunkie > Some(10)->flatMap(fn($x) => Some($x * 2))
$var2: Option = Some(20)

phunkie > $list = ImmList(1, 2, 3, 4, 5)
$var0: ImmList = List(1, 2, 3, 4, 5)

phunkie > $list->filter(fn($x) => $x > 2)
$var1: ImmList = List(3, 4, 5)

phunkie > $list->reduce(fn($acc, $x) => $acc + $x, 0)
$var2: Int = 15

phunkie > function double($x) {
phunkie {   return $x * 2;
phunkie { }
imported function double()

phunkie > double(21)
$var0: Int = 42

phunkie > :type ImmList(1, 2, 3)
ImmList

phunkie > :kind Option
* -> *

phunkie > :import strlen
imported function strlen()

phunkie > strlen("hello")
$var0: Int = 5

phunkie > :load helpers.php
// file helpers.php loaded

phunkie > // Now all functions and classes from helpers.php are available
bash
php vendor/bin/phunkie
bash
php vendor/bin/phunkie -c