Added insertAt, rewrote splitAt to use new helper#30
Added insertAt, rewrote splitAt to use new helper#30mrbackend wants to merge 1 commit intoelm-community:masterfrom mrbackend:master
Conversation
|
Awesome. It's some what surprising that we dont have I would like to merge this, but I have a few considerations: 0 The first of which, is that 1 Could you put in a code example in your docs? Something like what is in @knuton 's |
|
Dunno why this PR has never landed but fwiw and for those like me who're looking after insertAt : Int -> a -> List a -> List a
insertAt index item items =
let
(start, end) = splitAt index items
in
start ++ [ item ] ++ end |
Yes. I have a List because according to canonical Elm theory, Based on that advice, List is what I want, because with my use case, I'm recording moments in time and constantly adding them to the head of the list, and almost always access just the head. But just because that's what I do most often with my data structure, doesn't mean it's the only operations I may want to do with it. I'm building a function that will patch up some holes in the list (timeline) by backfilling a few moments (entries) that got synced from elsewhere. Thus I need to |
Added
insertAt. It is stack safe and about twice as fast as(take n xs) ++ (value :: drop n xs). As it happened, one of the helpers turned out to suitsplitAtvery well, so I rewrote that one to use the new helper. Fuzz tests forinsertAtincluded -splitAtalready had tests.Running elm-format 0.5.2-alpha introduced a couple of other modifications.