Skip to content

Commit

Permalink
Added associative array support for O::pick()
Browse files Browse the repository at this point in the history
  • Loading branch information
meszaros-lajos-gyorgy committed Jul 27, 2021
1 parent d8c2a1f commit 83d04e3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/O.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ public static function toPairs($data): array
}

// $coord = {x:10, y:20, z:30}; O::pick(['x', 'y'], $coord) -> {x:10, y:20}
public static function pick(array $keys, object $data): object
public static function pick(array $keys, $data): object
{
return A::reduce(
function ($result, $key) use ($data) {
if (isset($data->{$key})) {
$result->{$key} = $data->{$key};
if (self::has($key, $data)) {
$result->{$key} = self::prop($key, $data);
}
return $result;
},
Expand Down

0 comments on commit 83d04e3

Please sign in to comment.