prelude-generalize 0.3 → 0.3.1
raw patch · 2 files changed
+30/−3 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Prelude.Generalize: breakList :: ([a] -> Bool) -> [a] -> ([a], [a])
+ Prelude.Generalize: instance Swap ((,,) a)
+ Prelude.Generalize: instance Swap ((,,,) a b)
+ Prelude.Generalize: replace :: Eq a => [a] -> [a] -> [a] -> [a]
+ Prelude.Generalize: spanList :: ([a] -> Bool) -> [a] -> ([a], [a])
+ Prelude.Generalize: split :: (Alternative f, Eq a) => [a] -> [a] -> f [a]
+ Prelude.Generalize: subIndex :: (Peanoid i, Alternative f, Eq a) => [a] -> [a] -> f i
Files
- Prelude/Generalize.hs +29/−2
- prelude-generalize.cabal +1/−1
Prelude/Generalize.hs view
@@ -20,7 +20,8 @@ nubBy, deleteF, delete, group, insert, insertBy, intersect, intersectBy, partition, permutations, subsequences, transpose, union, unionBy, unzip4, unzip5, unzip6, unzip7, zip4, zip5, zip6, zip7, zipWith4, zipWith5, - zipWith6, zipWith7, lcomp, rcomp, loeb, Function(..) + zipWith6, zipWith7, lcomp, rcomp, loeb, Function(..), spanList, breakList, + split, replace, subIndex ) where { import Prelude hiding (head, tail, (!!), foldr, foldl, length, filter, mapM_, @@ -286,6 +287,14 @@ swap (x, y) = (y, x); }; + instance Swap ((,,) a) where { + swap (a, x, y) = (a, y, x); + }; + + instance Swap ((,,,) a b) where { + swap (a, b, x, y) = (a, b, y, x); + }; + instance Swap Either where { swap = either Right Left; }; @@ -531,7 +540,7 @@ findIndex :: (Peanoid i, Alternative f, Foldable t) => (a -> Bool) -> t a -> f i; findIndex p = snd . foldl (\(y, z) x -> (succP y, bool z (z <|> pure y) $ p x)) (zeroP, empty); {-# RULES "L.findIndex" findIndex = L.findIndex #-}; -{-# RULES "L.findIndices" findIndices = L.findIndices #-}; +{-# RULES "L.findIndices" findIndex = L.findIndices #-}; cycle :: Alternative f => f x -> f x; cycle x = x <|> cycle x; @@ -716,5 +725,23 @@ loeb :: (Function a (f b) b, Functor f) => f a -> f b; loeb x = ($ loeb x) <$> x; {-# SPECIALIZE loeb :: Functor f => f (f x -> x) -> f x #-}; + + spanList :: ([a] -> Bool) -> [a] -> ([a], [a]); + spanList _ [] = ([], []); + spanList f (h : t) = bool ([], h : t) (first (h :) $ spanList f t) $ f (h : t); + + breakList :: ([a] -> Bool) -> [a] -> ([a], [a]); + breakList = spanList . (not .); + + split :: (Alternative f, Eq a) => [a] -> [a] -> f [a]; + split _ [] = empty; + split d s = uncurry consA . second (\x -> bool (split d $ drop d x) (pure []) (d == x)) $ breakList (isPrefixOf d) s; +{-# SPECIALIZE split :: Eq a => [a] -> [a] -> [[a]] #-}; + + replace :: Eq a => [a] -> [a] -> [a] -> [a]; + replace o n = intercalate n . split o; + + subIndex :: (Peanoid i, Alternative f, Eq a) => [a] -> [a] -> f i; + subIndex x y = findIndex (isPrefixOf x) (tails y); }
prelude-generalize.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented. -Version: 0.3 +Version: 0.3.1 -- A short (one-line) description of the package. Synopsis: Another kind of alternate Prelude file