Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: something equivalent to "Array.prototype.fill" from ES6 #1

Open
PaulRBerg opened this issue Dec 26, 2022 · 1 comment

Comments

@PaulRBerg
Copy link
Contributor

PaulRBerg commented Dec 26, 2022

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:

  1. Add a new function fill that does only this.
  2. Modify the behavior of linspace to continue filling the output with duplicated values of the second argument (ustop).
@mds1
Copy link
Owner

mds1 commented Dec 27, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants