feat: reverse argument order of List.insert to index-first convention

The previous signature `insert(element, index)` was counter-intuitive and inconsistent with every major language's list API. This commit swaps the parameters to `insert(index, element)`, matching the convention used by Ruby, JavaScript, C++, Lua, C#, Java, and Python. All documentation, C implementation, and test files are updated to reflect the new order.
This commit is contained in:
Thorbjørn Lindeijer
2015-03-15 21:51:24 +00:00
parent 18cf57d5f5
commit 9a01d4b489
8 changed files with 24 additions and 24 deletions
+1 -1
View File
@@ -17,7 +17,7 @@ Removes all items from the list.
The number of items in the list.
### **insert**(item, index)
### **insert**(index, item)
**TODO**
+5 -5
View File
@@ -71,10 +71,10 @@ use `add` to append a single item to the end:
You can insert a new element at a specific position using `insert`:
:::dart
hirsute.insert("soul patch", 2)
hirsute.insert(2, "soul patch")
The first argument is the value to insert, and the second is the index to
insert it at. All elements following the inserted one will be pushed down to
The first argument is the index to insert at, and the second is the value to
insert. All elements following the inserted one will be pushed down to
make room for it.
It's valid to "insert" after the last element in the list, but only *right*
@@ -83,9 +83,9 @@ back. Doing so counts back from the size of the list *after* it's grown by one:
:::dart
var letters = ["a", "b", "c"]
letters.insert("d", 3) // OK: inserts at end.
letters.insert(3, "d") // OK: inserts at end.
IO.print(letters) // ["a", "b", "c", "d"]
letters.insert("e", -2) // Counts back from size after insert.
letters.insert(-2, "e") // Counts back from size after insert.
IO.print(letters) // ["a", "b", "c", "e", "d"]
## Removing elements