Skip to content

Instantly share code, notes, and snippets.

@chx

chx/pipe.php Secret

Created July 18, 2023 16:27
<?php
class p {
private array $callables = [];
public function __construct(private $value) {}
public function p(callable $callable) { $this->callables[] = $callable;return $this;}
public function __invoke() { foreach($this->callables as $callable) $this->value=$callable($this->value);return $this->value;}
}
$remove = ['noindex'];
print (new p('noindex, follow'))
->p(fn ($x) => explode(', ', $x))
->p(fn ($x) => array_diff($x, $remove))
->p(fn ($x) => implode(', ', $x))
();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment