Merged
Conversation
Collaborator
Collaborator
|
Also, here's a nice test to add to verify the final order is correct: fuzz2
(Fuzz.intRange 0 4)
(Fuzz.listOfLengthBetween 4 10 (Fuzz.intRange 0 10))
"index in bounds (0 <= index <= length) inserts in the right place in the list keeping the elements in the right order"
<|
\goodIndex list ->
List.Extra.insertAt goodIndex -1 list
|> List.Extra.removeAt goodIndex
|> Expect.equal list |
Contributor
Author
ah yes, that one's much better than mine, thanks! I've incorporated your notes in 587293c. Here's the benchmark on a second machine:
|
lue-bird
reviewed
Mar 22, 2026
|
|
||
| insertAtRecursion2Help : Int -> a -> List a -> Int -> List a -> List a -> List a | ||
| insertAtRecursion2Help index value list i rest acc = | ||
| if i == index then |
Collaborator
There was a problem hiding this comment.
Oh I forgot to mention that in my benchmarks this instead counts down from index and checks when it goes to 0. This avoids the extra i argument but should not be that much faster (not sure if comparisons with a literal are only optimized in eol2 or elm make)
Contributor
There was a problem hiding this comment.
It’s an Elm compiler optimization – comparisons with literals are faster.
Contributor
Author
|
@lue-bird 2x speedup for such a small change, that's awesome!
|
lue-bird
approved these changes
Mar 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The behaviour with out-of-bounds indexes mirrors
Array.Extra.insertAt.Benchmarks:
I chose the
splitAtapproach.splitAtapproach is 2x fastertakeDropapproach is faster, but this is still an edge case so I wouldn't give this too much weight