This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function tea_and_biscuits($tea, $biscuit) { | |
return $tea + ' ' + $biscuit; | |
} | |
$tea = 'tea'; | |
$tea_and_biscuits = partial($tea, (new _)); | |
$biscuits = ['chocolate', 'plain', 'hobnob']; | |
$tea_and_biscuits = array_map($tea_and_biscuits, $biscuits); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function cond($condition, callable $true, $false = NULL) { | |
if ($condition) { | |
return $true(); | |
} | |
if ($false !== NULL) { | |
if (is_callable($false)) { | |
return $false(); | |
} | |
throw new InvalidArgumentException('False not callable'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace _; | |
/** | |
* Data type to signify a placeholder. | |
*/ | |
class Placeholder {} | |
class_alias('Placeholder', '_'); | |
/** | |
* Creates a callback at the element of $iterator->current() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php $counter = (int) ($_GET['counter'] ?? 0); ?> | |
<form> | |
<button name="counter" value="<?= $counter + 1 ?>">Number <?= $counter ?></button> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function recursive_filter($data, callable $selector_function, $iterator = NULL) { | |
$iterator = $iterator ?? new RecursiveIteratorIterator( | |
new RecursiveArrayIterator($data), | |
RecursiveIteratorIterator::CHILD_FIRST | |
); | |
foreach ($iterator as $key => $value) { | |
if ($selector_function($value, $key, $iterator)) { | |
$depth = $iterator->getDepth(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace _; | |
/** | |
* Data type to signify a placeholder. | |
*/ | |
class Placeholder {} | |
class_alias('Placeholder', '_'); | |
/** | |
* Creates a callback at the element of $iterator->current() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* @file | |
* Collection of functional tools. | |
*/ | |
namespace _; | |
/** | |
* Creates a callback at the element of $iterator->current() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class struct { | |
function __invoke(callable $callback) { | |
return $callback(...array_values($this->props)); | |
} | |
} | |
class box extends struct { | |
function __construct($a, $b) { | |
$this->props = get_defined_vars(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Struct { | |
private $args; | |
function __construct(array $args) { | |
$this->args = $args; | |
} | |
function __invoke(callable $signature) { | |
return $signature(...array_values($this->args)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Event storage. | |
function event_storage(callable $callback) { | |
static $storage = array(); | |
return $storage = $callback($storage); | |
} | |
// Retrieve events. | |
function event_get(callable $filter) { |