packages feed

mono-traversable 1.0.1.3 → 1.0.2

raw patch · 3 files changed

+20/−1 lines, 3 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Data.Sequences: lengthIndex :: IsSequence seq => seq -> Index seq
- Data.Sequences: class (Monoid seq, MonoTraversable seq, SemiSequence seq, MonoPointed seq) => IsSequence seq where fromList = mconcat . fmap singleton break f = (fromList *** fromList) . break f . otoList span f = (fromList *** fromList) . span f . otoList dropWhile f = fromList . dropWhile f . otoList takeWhile f = fromList . takeWhile f . otoList splitAt i = (fromList *** fromList) . genericSplitAt i . otoList unsafeSplitAt i seq = (unsafeTake i seq, unsafeDrop i seq) take i = fst . splitAt i unsafeTake = take drop i = snd . splitAt i unsafeDrop = drop partition f = (fromList *** fromList) . partition f . otoList uncons = fmap (second fromList) . uncons . otoList unsnoc = fmap (first fromList) . unsnoc . otoList filter f = fromList . filter f . otoList filterM f = liftM fromList . filterM f . otoList replicate i = fromList . genericReplicate i replicateM i = liftM fromList . replicateM (fromIntegral i) groupBy f = fmap fromList . groupBy f . otoList groupAllOn f = fmap fromList . groupAllOn f . otoList subsequences = map fromList . subsequences . otoList permutations = map fromList . permutations . otoList tailEx = snd . maybe (error "Data.Sequences.tailEx") id . uncons tailMay seq | onull seq = Nothing | otherwise = Just (tailEx seq) initEx = fst . maybe (error "Data.Sequences.initEx") id . unsnoc initMay seq | onull seq = Nothing | otherwise = Just (initEx seq) unsafeTail = tailEx unsafeInit = initEx index seq' idx = headMay (drop idx seq') indexEx seq' idx = maybe (error "Data.Sequences.indexEx") id (index seq' idx) unsafeIndex = indexEx splitWhen = defaultSplitWhen
+ Data.Sequences: class (Monoid seq, MonoTraversable seq, SemiSequence seq, MonoPointed seq) => IsSequence seq where fromList = mconcat . fmap singleton lengthIndex = fromIntegral . olength64 break f = (fromList *** fromList) . break f . otoList span f = (fromList *** fromList) . span f . otoList dropWhile f = fromList . dropWhile f . otoList takeWhile f = fromList . takeWhile f . otoList splitAt i = (fromList *** fromList) . genericSplitAt i . otoList unsafeSplitAt i seq = (unsafeTake i seq, unsafeDrop i seq) take i = fst . splitAt i unsafeTake = take drop i = snd . splitAt i unsafeDrop = drop partition f = (fromList *** fromList) . partition f . otoList uncons = fmap (second fromList) . uncons . otoList unsnoc = fmap (first fromList) . unsnoc . otoList filter f = fromList . filter f . otoList filterM f = liftM fromList . filterM f . otoList replicate i = fromList . genericReplicate i replicateM i = liftM fromList . replicateM (fromIntegral i) groupBy f = fmap fromList . groupBy f . otoList groupAllOn f = fmap fromList . groupAllOn f . otoList subsequences = map fromList . subsequences . otoList permutations = map fromList . permutations . otoList tailEx = snd . maybe (error "Data.Sequences.tailEx") id . uncons tailMay seq | onull seq = Nothing | otherwise = Just (tailEx seq) initEx = fst . maybe (error "Data.Sequences.initEx") id . unsnoc initMay seq | onull seq = Nothing | otherwise = Just (initEx seq) unsafeTail = tailEx unsafeInit = initEx index seq' idx = headMay (drop idx seq') indexEx seq' idx = maybe (error "Data.Sequences.indexEx") id (index seq' idx) unsafeIndex = indexEx splitWhen = defaultSplitWhen

Files

ChangeLog.md view
@@ -1,3 +1,7 @@+## 1.0.2++* `IsSequence` class: add `lengthIndex` [#127](https://github.com/snoyberg/mono-traversable/pull/127)+ ## 1.0.1.3  * Make 'olength' for Set and Map O(1) [#125](https://github.com/snoyberg/mono-traversable/pull/125)
mono-traversable.cabal view
@@ -1,5 +1,5 @@ name:                mono-traversable-version:             1.0.1.3+version:             1.0.2 synopsis:            Type classes for mapping, folding, and traversing monomorphic containers description:         Monomorphic variants of the Functor, Foldable, and Traversable typeclasses. If you understand Haskell's basic typeclasses, you understand mono-traversable. In addition to what you are used to, it adds on an IsSequence typeclass and has code for marking data structures as non-empty. homepage:            https://github.com/snoyberg/mono-traversable
src/Data/Sequences.hs view
@@ -145,6 +145,12 @@     -- However, all the instances define their own fromList     fromList = mconcat . fmap singleton +    -- | 'lengthIndex' returns the length of a sequence as @'Index' seq@.+    --+    -- @since 1.0.2+    lengthIndex :: seq -> Index seq;+    lengthIndex = fromIntegral . olength64;+     -- below functions change type fron the perspective of NonEmpty      -- | 'break' applies a predicate to a sequence, and returns a tuple where@@ -558,6 +564,7 @@  instance IsSequence [a] where     fromList = id+    lengthIndex = List.length     filter = List.filter     filterM = Control.Monad.filterM     break = List.break@@ -637,6 +644,7 @@  instance IsSequence S.ByteString where     fromList = S.pack+    lengthIndex = S.length     replicate = S.replicate     filter = S.filter     break = S.break@@ -706,6 +714,7 @@  instance IsSequence T.Text where     fromList = T.pack+    lengthIndex = T.length     replicate i c = T.replicate i (T.singleton c)     filter = T.filter     break = T.break@@ -768,6 +777,7 @@  instance IsSequence L.ByteString where     fromList = L.pack+    lengthIndex = L.length     replicate = L.replicate     filter = L.filter     break = L.break@@ -827,6 +837,7 @@  instance IsSequence TL.Text where     fromList = TL.pack+    lengthIndex = TL.length     replicate i c = TL.replicate i (TL.singleton c)     filter = TL.filter     break = TL.break@@ -886,6 +897,7 @@  instance IsSequence (Seq.Seq a) where     fromList = Seq.fromList+    lengthIndex = Seq.length     replicate = Seq.replicate     replicateM = Seq.replicateM     filter = Seq.filter@@ -953,6 +965,7 @@  instance IsSequence (V.Vector a) where     fromList = V.fromList+    lengthIndex = V.length     replicate = V.replicate     replicateM = V.replicateM     filter = V.filter@@ -1027,6 +1040,7 @@  instance U.Unbox a => IsSequence (U.Vector a) where     fromList = U.fromList+    lengthIndex = U.length     replicate = U.replicate     replicateM = U.replicateM     filter = U.filter@@ -1101,6 +1115,7 @@  instance VS.Storable a => IsSequence (VS.Vector a) where     fromList = VS.fromList+    lengthIndex = VS.length     replicate = VS.replicate     replicateM = VS.replicateM     filter = VS.filter