Re: Proposal #3271: new methods for Data.Sequence

As a final addition to Data.Sequence, I've addedhttp://hackage.haskell.org/trac/ghc/attachment/ticket/3271/new-methods-for-d...the following methods. Possibly debatable design decisions are highlighted. - mapWithIndex :: (Int -> a -> b) -> Seq a -> Seq b. (This is based on mapAccumL, which is slightly suboptimal [as the full mapping must be done before the last element can be examined], but acceptable given the tiny code investment.) - elemIndex, elemIndices, findIndex, findIndices, all as in Data.List. - elemLastIndex, findLastIndex, elemIndicesDesc, findIndicesDesc, all working from right-to-left but otherwise analogous. **Note:**findIndicesDesc and elemIndicesDesc return lists, not Sequences, so as to permit maximum laziness. Moreover, both of those methods fuse well. - takeWhileEnd, dropWhileEnd, spanEnd, breakEnd, all of which work from right-to-left but otherwise perform as their Data.List analogues. * *Note:** spanEnd p xs, in particular, returns *first* the longest *suffix * of xs of elements satisfying p, and then the remaining prefix. All but mapWithIndex take O(i) time, where i is the appropriate breakpoint -- that is, they don't necessarily search the entire sequence. (Each of the xxxEnd methods take O(n-i).) None of these methods are particularly code-intensive, save for some rewrite-rules-based code that lets most of those methods be defined in terms of findIndex, without any performance loss. (In the absence of rewrite rules, the additional overhead is small.) Louis Wasserman wasserman.louis@gmail.com
participants (1)
-
Louis Wasserman