pipeline icon indicating copy to clipboard operation
pipeline copied to clipboard

Preserve keys?

Open jenky opened this issue 1 year ago • 1 comments

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

jenky avatar Apr 30 '23 16:04 jenky