-
-
Notifications
You must be signed in to change notification settings - Fork 0
[RFC]: add array/base/to-filled #292
Copy link
Copy link
Open
stdlib-js/stdlib
#11954Labels
FeatureTask to add a new feature.Task to add a new feature.difficulty: 2May require some initial design or R&D, but should be straightforward to resolve and/or implement.May require some initial design or R&D, but should be straightforward to resolve and/or implement.estimate: <2hrsTask which should take less than 2 hours.Task which should take less than 2 hours.priority: NormalNormal priority concern or feature request.Normal priority concern or feature request.🤖 AIAllowed to use AI.Allowed to use AI.
Metadata
Metadata
Assignees
Labels
FeatureTask to add a new feature.Task to add a new feature.difficulty: 2May require some initial design or R&D, but should be straightforward to resolve and/or implement.May require some initial design or R&D, but should be straightforward to resolve and/or implement.estimate: <2hrsTask which should take less than 2 hours.Task which should take less than 2 hours.priority: NormalNormal priority concern or feature request.Normal priority concern or feature request.🤖 AIAllowed to use AI.Allowed to use AI.
This is the copying version of
array/base/fill(which mutates) and a generalization ofarray/base/with(which only sets a single element).The naive approach would be to simply copy (using
array/base/slice) an input array (similar toarray/base/with) and then overwrite the specified fill region. This should be fine, even if less optimal for array-like objects lacking a#.slicemethod.The alternative would be to allocate a new array, copy values from the original array up until start, fill the specified region, and then copy values from the end index to the end of the original array. In principle, this approach would be better. In practice, it is likely to be less efficient, as built-in array slice operations are likely to use
memcpywhich is going to be faster than anything we do in userland.Similar to
array/base/with, we can provide anassignAPI. Accordingly, the proposed signatures: