-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
103 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bentools\ETL; | ||
|
||
use function array_fill_keys; | ||
use function array_intersect_key; | ||
use function array_replace; | ||
|
||
/** | ||
* @param list<string> $keys | ||
* @param array<string, mixed> $values | ||
* @param array<string, mixed> ...$extraValues | ||
* | ||
* @return array<string, mixed> | ||
*/ | ||
function array_fill_from(array $keys, array $values, array ...$extraValues): array | ||
{ | ||
$defaults = array_fill_keys($keys, null); | ||
$values = array_replace($values, ...$extraValues); | ||
|
||
return array_intersect_key($values, $defaults); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace BenTools\ETL\Tests\Unit; | ||
|
||
use function Bentools\ETL\array_fill_from; | ||
use function expect; | ||
|
||
it('produces a new array with the provided keys', function () { | ||
// Given | ||
$food = [ | ||
'a' => 'Apple', | ||
'b' => 'Banana', | ||
'c' => 'Carrot', | ||
'd' => 'Dill', | ||
]; | ||
|
||
// When | ||
$result = array_fill_from(['a', 'b', 'e'], $food, ['b' => 'banana', 'f' => 'Fig']); | ||
|
||
// Then | ||
expect($result)->toBe([ | ||
'a' => 'Apple', | ||
'b' => 'banana', | ||
]); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters