Last active
August 29, 2015 14:12
-
-
Save pawlik/5189e75a4ccbd52fa589 to your computer and use it in GitHub Desktop.
is ruby like tap possible in php even in ?
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 Tappable { | |
private $whatever = null; | |
public function __construct($whatever) { | |
$this->whatever = $whatever; | |
} | |
public function tap(callable $callback) { | |
$callback($this->whatever); | |
return $this->whatever; | |
} | |
} | |
$callback = function($h){ | |
echo "do sth with $h\n"; | |
echo "do sth else with $h\n"; | |
}; | |
// anyway you have to pollute your namespace here: | |
$x = new Tappable("123"); | |
$x->tap($callback); | |
// because this will not work in php <= 5.6.4 | |
(new Tappable("hakunamatata")).tap($callback); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment