Skip to content

[RFC]: add array/base/to-filled #292

@kgryte

Description

@kgryte

This is the copying version of array/base/fill (which mutates) and a generalization of array/base/with (which only sets a single element).

The naive approach would be to simply copy (using array/base/slice) an input array (similar to array/base/with) and then overwrite the specified fill region. This should be fine, even if less optimal for array-like objects lacking a #.slice method.

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 memcpy which is going to be faster than anything we do in userland.

Similar to array/base/with, we can provide an assign API. Accordingly, the proposed signatures:

toFilled( x, value, start, end );
toFilled.assign( x, value, start, end, out, strideOut, offsetOut );

Metadata

Metadata

Assignees

Labels

FeatureTask to add a new feature.difficulty: 2May 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.priority: NormalNormal priority concern or feature request.🤖 AIAllowed to use AI.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions