utility-ht 0.0.3 → 0.0.4
raw patch · 8 files changed
+111/−14 lines, 8 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Control.Monad.HT: (<=<) :: (Monad m) => (b -> m c) -> (a -> m b) -> (a -> m c)
+ Data.List.HT: break :: (a -> Bool) -> [a] -> ([a], [a])
+ Data.List.HT: span :: (a -> Bool) -> [a] -> ([a], [a])
+ Data.Maybe.HT: (?->) :: Maybe a -> (a -> b) -> Maybe b
+ Data.Maybe.HT: alternatives :: a -> [Maybe a] -> a
+ Data.String.HT: trim :: String -> String
Files
- src/Control/Monad/HT.hs +10/−0
- src/Data/List/HT.hs +2/−0
- src/Data/List/HT/Private.hs +36/−6
- src/Data/List/Key/Private.hs +6/−5
- src/Data/Maybe/HT.hs +36/−0
- src/Data/String/HT.hs +8/−0
- src/Data/Tuple/HT.hs +10/−1
- utility-ht.cabal +3/−2
src/Control/Monad/HT.hs view
@@ -3,6 +3,16 @@ import Control.Monad (liftM, liftM2, ) import Prelude hiding (repeat, until, ) ++infixr 1 <=<++{- |+Also present in newer versions of the 'base' package.+-}+(<=<) :: Monad m => (b -> m c) -> (a -> m b) -> (a -> m c)+(<=<) f g = (f =<<) . g++ {- | Monadic 'List.repeat'. -}
src/Data/List/HT.hs view
@@ -6,6 +6,8 @@ L.group, L.unzip, L.partition,+ L.span,+ L.break, -- * Split L.chop, L.breakAfter,
src/Data/List/HT/Private.hs view
@@ -10,7 +10,7 @@ import qualified Data.List.Key.Private as Key import qualified Data.List.Match.Private as Match -import Prelude hiding (unzip, )+import Prelude hiding (unzip, break, span, ) -- * Improved standard functions@@ -114,7 +114,24 @@ else (y, x : z)) ([],[]) +{- |+It is @Data.List.span f undefined = undefined@,+whereas @span f undefined = (undefined, undefined)@.+-}+span, break :: (a -> Bool) -> [a] -> ([a],[a])+span p =+ let recourse xt =+ forcePair $+ fromMaybe ([],xt) $+ do (x,xs) <- viewL xt+ guard $ p x+ return $ mapFst (x:) $ recourse xs+ in recourse +break p = span (not . p)+++ -- * Split {- |@@ -123,13 +140,19 @@ This is a generalization of 'words'. -} chop :: (a -> Bool) -> [a] -> [[a]]-chop p s =- let (l, s') = break p s- in l : case s' of- [] -> []- (_:rest) -> chop p rest+chop p =+ uncurry (:) .+ foldr (\ x ~(y,ys) -> if p x then ([],y:ys) else ((x:y),ys) ) ([],[]) +chop' :: (a -> Bool) -> [a] -> [[a]]+chop' p =+ let recourse =+ uncurry (:) .+ mapSnd (switchL [] (const recourse)) .+ break p+ in recourse + chopAtRun :: (Eq a) => (a -> Bool) -> [a] -> [[a]] chopAtRun p = let recourse [] = [[]]@@ -372,6 +395,9 @@ {- | Partition a list into elements which evaluate to @Just@ or @Nothing@ by @f@.++It holds @mapMaybe f == fst . partitionMaybe f@+and @partition p == partitionMaybe (\ x -> toMaybe (p x) x)@. -} partitionMaybe :: (a -> Maybe b) -> [a] -> ([b], [a]) partitionMaybe f =@@ -727,6 +753,10 @@ isAscendingLazy :: (Ord a) => [a] -> [Bool] isAscendingLazy = mapAdjacent (<=) +{- |+This function combines every pair of neighbour elements+in a list with a certain function.+-} mapAdjacent :: (a -> a -> b) -> [a] -> [b] mapAdjacent f xs = zipWith f xs (tail xs)
src/Data/List/Key/Private.hs view
@@ -101,10 +101,11 @@ mergeBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] mergeBy p =- let recourse xl@(x:xs) yl@(y:ys) =- if p x y- then x : recourse xs yl- else y : recourse xl ys- recourse [] yl = yl+ let recourse [] yl = yl recourse xl [] = xl+ recourse xl@(x:xs) yl@(y:ys) =+ uncurry (:) $+ if p x y+ then (x, recourse xs yl)+ else (y, recourse xl ys) in recourse
src/Data/Maybe/HT.hs view
@@ -1,8 +1,44 @@ module Data.Maybe.HT where +import Data.Maybe (fromMaybe, )+import Control.Monad (msum, )++ {- | Returns 'Just' if the precondition is fulfilled. -} {-# INLINE toMaybe #-} toMaybe :: Bool -> a -> Maybe a toMaybe False _ = Nothing toMaybe True x = Just x ++infixl 6 ?->++{- |+This is an infix version of 'fmap'+for writing 'Data.Bool.HT.select' style expressions+using test functions, that produce 'Maybe's.++The precedence is chosen to be higher than '(:)',+in order to allow:++> alternatives default $+> checkForA ?-> (\a -> f a) :+> checkForB ?-> (\b -> g b) :+> []++The operation is left associative+in order to allow to write++> checkForA ?-> f ?-> g++which is equivalent to++> checkForA ?-> g . f++due to the functor law.+-}+(?->) :: Maybe a -> (a -> b) -> Maybe b+(?->) = flip fmap++alternatives :: a -> [Maybe a] -> a+alternatives deflt = fromMaybe deflt . msum
+ src/Data/String/HT.hs view
@@ -0,0 +1,8 @@+module Data.String.HT where++import Data.Char (isSpace, )+import Data.List.HT (dropWhileRev, )++-- | remove leading and trailing spaces+trim :: String -> String+trim = dropWhileRev isSpace . dropWhile isSpace
src/Data/Tuple/HT.hs view
@@ -2,7 +2,16 @@ -- * Pair --- | '(Control.Arrow.***)'+{- | Cf. '(Control.Arrow.***)'.++Apply two functions on corresponding values in a pair,+where the pattern match on the pair constructor is lazy.+This is crucial in recursions such as the of 'partition'.+-}+{-+Instead of pattern matching with \code{(x,y)}+we may use \function{fst} and \function{snd}.+-} {-# INLINE mapPair #-} mapPair :: (a -> c, b -> d) -> (a,b) -> (c,d) mapPair ~(f,g) ~(x,y) = (f x, g y)
utility-ht.cabal view
@@ -1,5 +1,5 @@ Name: utility-ht-Version: 0.0.3+Version: 0.0.4 License: BSD3 License-File: LICENSE Author: Henning Thielemann <haskell@henning-thielemann.de>@@ -27,7 +27,7 @@ Source-Repository this type: darcs location: http://code.haskell.org/~thielema/utility/- tag: 0.0.3+ tag: 0.0.4 Library@@ -47,6 +47,7 @@ Data.Record.HT Data.Tuple.HT Control.Monad.HT+ Data.String.HT Text.Read.HT Text.Show.HT Other-Modules: