Anomalous `assocPath` function behavior
Closed this issue · 1 comments
The purpose of the assocPath()
function is to create a shallow clone of a list with an overwritten value assigned to the index at the end of a (specified) traversable path. The current behavior is such that a call to the said function appends - to a target list - a discretionary value whose index is the first item in the specified path - in the event that the said path does not exist. Consider the example to follow.
use function Chemem\Bingo\Functional\assocPath;
$list = assocPath(['foo', 'bar'], 2, ['bar' => 2]);
var_dump($list);
The output of the snippet above - per the current constitution of the assocPath()
function signature - is as follows.
array(2) {
["bar"]=>
int(2)
["foo"]=>
int(2)
}
The result depicted above is erroneous and invalidates the assocPath()
function. The correct result is a clone of the original array - that contains a new entry: a hashtable with a single dimension that corresponds to the path 'foo' -> 'bar'
. The aberrant behavior depicted in the previous snippet - upon correction - should produce output similar to that in the snippet below.
array(2) {
["bar"]=>
int(2)
["foo"]=>
array(1) {
["bar"]=>
int(2)
}
}