Skip to content

Commit 6f021df

Browse files
authored
Merge pull request #7 from infocyph/feature/improvement-25
updated to add common functions
2 parents 310d252 + e87939b commit 6f021df

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/functions.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
declare(strict_types=1);
44

55

6+
use Infocyph\ArrayKit\Collection\Collection;
7+
68
if (!function_exists('compare')) {
79
/**
810
* Compare two values using a specified operator.
@@ -57,7 +59,7 @@ function isCallable(mixed $value): bool
5759
* @param mixed $default The default value to return if the key is not found.
5860
* @return mixed The retrieved value(s).
5961
*/
60-
function array_get(array $array, int|string|array $key = null, mixed $default = null): mixed
62+
function array_get(array $array, int|string|array|null $key = null, mixed $default = null): mixed
6163
{
6264
return Infocyph\ArrayKit\Array\DotNotation::get($array, $key, $default);
6365
}
@@ -82,3 +84,15 @@ function array_set(array &$array, string|array|null $key, mixed $value = null, b
8284
return Infocyph\ArrayKit\Array\DotNotation::set($array, $key, $value, $overwrite);
8385
}
8486
}
87+
if (!function_exists('collect')) {
88+
/**
89+
* Wrap the given value in an {@see Collection}.
90+
*
91+
* @param mixed $data Anything “array-able”: array, Traversable, scalar, etc.
92+
* @return Collection
93+
*/
94+
function collect(mixed $data = []): Collection
95+
{
96+
return Collection::make($data);
97+
}
98+
}

0 commit comments

Comments
 (0)