Last active
August 29, 2015 14:13
-
-
Save thekid/03064f037d5b426404c2 to your computer and use it in GitHub Desktop.
Brainstorming for sequence handling split based on element criteria
This file contains hidden or 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 | |
| use util\data\Sequence; | |
| class Types extends \lang\Enum { | |
| public static $OPEN, $CLOSED; | |
| } | |
| class Wall extends \lang\Object { | |
| private $name, $type; | |
| public function __construct($name, Types $type) { | |
| $this->name= $name; | |
| $this->type= $type; | |
| } | |
| public function name() { return $this->name; } | |
| public function type() { return $this->type; } | |
| } | |
| class Test extends \lang\Object { | |
| static function __static() { Types::__static(); } | |
| public static function main($args) { | |
| Sequence::of([new Wall('My Team', Types::$CLOSED), new Wall('Developers', Types::$OPEN)]) | |
| ->map(function($wall) { | |
| if (Types::$OPEN === $wall->type()) { | |
| return 'Open walls like '.$wall->name().' are great'; | |
| } else { | |
| return 'Closed walls make sense sometimes, e.g. for '.$wall->name(); | |
| } | |
| }) | |
| ->each('util.cmd.Console::writeLine') | |
| ; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See https://github.com/xp-forge/match for the API itself and the performance figures