-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from ace411/v2.x
v2.2.0 changes
- Loading branch information
Showing
16 changed files
with
559 additions
and
45 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* equals function | ||
* | ||
* @package bingo-functional | ||
* @author Lochemem Bruno Michael | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
namespace Chemem\Bingo\Functional; | ||
|
||
use function Chemem\Bingo\Functional\Internal\_refobj; | ||
|
||
const equals = __NAMESPACE__ . '\\equals'; | ||
|
||
/** | ||
* equals | ||
* perform artifact comparisons to ascertain equivalence | ||
* | ||
* equals :: a -> b -> Bool -> Bool | ||
* | ||
* @param mixed $fst | ||
* @param mixed $snd | ||
* @param boolean $recurse | ||
* @return boolean | ||
* @example | ||
* | ||
* equals((object)range(1, 5), (object)range(2, 4)); | ||
* => false | ||
*/ | ||
function equals($fst, $snd, bool $recurse = false): bool | ||
{ | ||
$ft = \gettype($fst); | ||
$st = \gettype($snd); | ||
// store core types in list to preempt redeclaration | ||
$core = [ | ||
'integer', | ||
'string', | ||
'boolean', | ||
'array', | ||
'double', | ||
'NULL', | ||
]; | ||
|
||
if ($ft !== $st) { | ||
return false; | ||
} | ||
|
||
if (\in_array($ft, $core) && \in_array($st, $core)) { | ||
return $fst === $snd; | ||
} | ||
|
||
if ($ft === 'resource' && $st === 'resource') { | ||
return \get_resource_type($fst) === \get_resource_type($snd); | ||
} | ||
|
||
if ($ft === 'object' && $st === 'object') { | ||
return _refobj($fst, $recurse) === _refobj($snd, $recurse); | ||
} | ||
|
||
return false; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,5 +27,5 @@ | |
*/ | ||
function head($list, $def = null) | ||
{ | ||
return \reset($list); | ||
return \reset($list) ?? $def; | ||
} |
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
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
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
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
Oops, something went wrong.