Skip to content

Commit 9f13cb7

Browse files
is_empty
1 parent 7270cce commit 9f13cb7

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"src/AtLeast.php",
3636
"src/AtMost.php",
3737
"src/Exactly.php",
38+
"src/IsEmpty.php",
3839
"src/Add.php",
3940
"src/Set.php",
4041
"src/Pipe.php",

src/IsEmpty.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace BrenoRoosevelt;
5+
6+
use Throwable;
7+
use Traversable;
8+
9+
/**
10+
* @param array|Traversable $haystack
11+
* @return bool
12+
*/
13+
function is_empty($haystack): bool
14+
{
15+
$tmp = $haystack;
16+
try {
17+
if (is_object($haystack)) {
18+
$tmp = clone $haystack;
19+
}
20+
} catch (Throwable $exception) {
21+
}
22+
23+
foreach ($tmp as $item) {
24+
return false;
25+
}
26+
27+
return true;
28+
}

0 commit comments

Comments
 (0)