Skip to content

Commit

Permalink
Add support for <=> to fn\operator()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Jul 3, 2015
1 parent e9c2ab7 commit 7da440d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/iter.fn.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ function operator($operator, $arg = null) {
'&&' => function($a, $b) { return $a && $b; },
'||' => function($a, $b) { return $a || $b; },
'**' => function($a, $b) { return \pow($a, $b); },
'<=>' => function($a, $b) {
return $a == $b ? 0 : ($a < $b ? -1 : 1);
},
];

if (!isset($functions[$operator])) {
Expand Down
4 changes: 4 additions & 0 deletions test/IterFnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public function provideTestOperator() {
['&&', true, false, false],
['||', true, false, true],
['**', 2, 4, 16],
['<=>', [0=>1,1=>0], [1=>0,0=>1], 0],
['<=>', '2e1', '1e10', -1],
['<=>', new \stdClass(), new \SplStack(), 1],
['<=>', new \SplStack(), new \stdClass(), 1],
];
}

Expand Down

0 comments on commit 7da440d

Please sign in to comment.