Skip to content

Proposal: Change other methods to not returning booleans and clamping indexes #9

@Mitsunee

Description

@Mitsunee

insertMany replaced insertArray and insertList while also changing the return value:

insertArray(index: number, values: Array<T>): boolean
// vs
insertMany(index: number, values: Iterable<T>): this

This is done by clamping the index to be from 0 to this.length, so any negative indeces become 0 and thus values are added to the start of the list, and the same for indeces larger than this.length adding to the end.

That frees up the return value, which previously reported on whether the index was accepted. My proposal is to apply this logic to every other function with a similar index parameter by implementing the following method to use on every index parameter:

private clampIndex(index: number) {
  if (index < 0) return 0;
  if (index > this.length) return this.length;
  return Math.trunc(index);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    Ideas

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions