Skip to content

Commit

Permalink
Cast array keys as string by default in Flip operation.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 6, 2019
1 parent eb98244 commit 905d3fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions spec/drupol/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,19 @@ public function it_can_flip(): void
$this
->flip()
->shouldIterateAs(['A' => 0, 'B' => 1, 'C' => 2, 'D' => 3, 'E' => 4]);

$input = [3/2, 4/3, 5/4, 6/5, 9/8];
$output = [
'1.5' => 0,
'1.3333333333333' => 1,
'1.25' => 2,
'1.2' => 3,
'1.125' => 4,
];

$this::with($input)
->flip()
->shouldIterateAs($output);
}

public function it_can_forget(): void
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/Flip.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function on(iterable $collection): Closure
{
return static function () use ($collection): Generator {
foreach ($collection as $key => $value) {
yield $value => $key;
yield (string) $value => $key;
}
};
}
Expand Down

0 comments on commit 905d3fb

Please sign in to comment.