Skip to content

Proposal: add a builtin splice function for easier slice handling #14991

@urandom

Description

@urandom

This proposal is for adding a builtin splice function for adding/removing items in a slice:

splice(slice []Type, start, deleteCount int, elems ...Type) []Type

While the builtin append function can do everything that a splice function can, its a lot trickier to use for anything other than append, even by experienced go users. Newcomers to the language struggle with simple tasks of slice modification, and there are a lot of posted questions about them. It doesn't help that a function named append is supposed to be used for removing items from a slice.

On the other hand, people might be familiar with the splice function and its notation from other mainstream languages.

It doesn't seem like much, but it's a low hanging fruit that will help people new to the language.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions