Skip to content

Commit 618fae7

Browse files
committed
increased flexibility in pluck and keyBy
1 parent 788c191 commit 618fae7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Types/AbstractCypherSequence.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public function pluck(string $key): ArrayList
289289
{
290290
return new ArrayList(function () use ($key) {
291291
foreach ($this as $value) {
292-
if (is_array($value) && array_key_exists($key, $value)) {
292+
if ((is_array($value) && array_key_exists($key, $value)) || ($value instanceof ArrayAccess && $value->offsetExists($key))) {
293293
yield $value[$key];
294294
} elseif (is_object($value) && property_exists($value, $key)) {
295295
yield $value->$key;
@@ -309,7 +309,7 @@ public function keyBy(string $key): Map
309309
{
310310
return new Map(function () use ($key) {
311311
foreach ($this as $value) {
312-
if (is_array($value) && array_key_exists($key, $value) && $this->isStringable($value[$key])) {
312+
if (((is_array($value) && array_key_exists($key, $value)) || ($value instanceof ArrayAccess && $value->offsetExists($key))) && $this->isStringable($value[$key])) {
313313
yield $value[$key] => $value;
314314
} elseif (is_object($value) && property_exists($value, $key) && $this->isStringable($value->$key)) {
315315
yield $value->$key => $value;

0 commit comments

Comments
 (0)