Preserve keys?
jenky opened this issue · 1 comments
jenky commented
Pipeline::fromIterable(['a' => 1, 'b' => 2, 'c' => 3])
->map(fn (int $n) => $n * 2)
->toArray();
gives the following result
^ array:3 [
0 => 2
1 => 4
2 => 6
]
However, I expect the result should be
^ array:3 [
'a' => 2
'b' => 4
'c' => 6
]
I see toArray
method use \iterator_to_array($this, false)
which set $preserve_keys
to false
. But using \iterator_to_array($pipeline)
also gives the same result
kelunik commented
Keys aren't supported in pipelines, if you need them, you can use an array like [$key, $value]
.