solidity-generators
solidity-generators copied to clipboard
Feature request: something equivalent to "Array.prototype.fill" from ES6
See Array.prototype.fill. When used like this in JavaScript:
Array(5).fill(2)
It will yield the following output:
[2, 2, 2, 2, 2]
It seems to me that solidity-generators would be the right place to implement such a functionality in Solidity (better than forge-std).
The way I see it, there are a couple ways this could be implemented:
- Add a new function
fillthat does only this. - Modify the behavior of
linspaceto continue filling the output with duplicated values of the second argument (ustop).
Agreed, this does seem like the right library for this method.
The existing function names/signatures are modeled after numpy's method's of the same name, so perhaps we base this one on the full method:
>>> np.full(5, 2)
array([2, 2, 2, 2, 2])
function full(uint length, uint val) pure returns (uint[] memory arr) {
// --- snip ---
}
I won't be able to implement this until after the holidays, but PRs definitely welcome if you want it sooner