packages feed

utility-ht 0.0.9 → 0.0.10

raw patch · 6 files changed

+118/−13 lines, 6 files

Files

src/Control/Functor/HT.hs view
@@ -1,4 +1,19 @@ module Control.Functor.HT where +import Data.Tuple.HT (fst3, snd3, thd3, )++ void :: Functor f => f a -> f () void = fmap (const ())++map :: Functor f => (a -> b) -> f a -> f b+map = fmap++for :: Functor f => f a -> (a -> b) -> f b+for = flip fmap++unzip :: Functor f => f (a, b) -> (f a, f b)+unzip x = (fmap fst x, fmap snd x)++unzip3 :: Functor f => f (a, b, c) -> (f a, f b, f c)+unzip3 x = (fmap fst3 x, fmap snd3 x, fmap thd3 x)
src/Control/Monad/HT.hs view
@@ -1,6 +1,6 @@ module Control.Monad.HT where -import Control.Monad (liftM, liftM2, )+import qualified Control.Monad as M import Prelude hiding (repeat, until, )  @@ -18,7 +18,7 @@ -} repeat :: (Monad m) => m a -> m [a] repeat x =-   let go = liftM2 (:) x go in go+   let go = lift2 (:) x go in go  {-# DEPRECATED untilM "use M.until" #-} {- | repeat action until result fulfills condition -}@@ -38,7 +38,7 @@ iterateLimitM = iterateLimit iterateLimit m f =    let aux n x =-          liftM (x:) $+          lift (x:) $           if n==0             then return []             else aux (n-1) =<< f x@@ -70,4 +70,54 @@   void :: (Monad m) => m a -> m ()-void = liftM (const ())+void = lift (const ())++for :: Monad m => [a] -> (a -> m b) -> m [b]+for = M.forM++map :: Monad m => (a -> m b) -> [a] -> m [b]+map = M.mapM++zipWith :: Monad m => (a -> b -> m c) -> [a] -> [b] -> m [c]+zipWith = M.zipWithM++filter :: Monad m => (a -> m Bool) -> [a] -> m [a]+filter = M.filterM++replicate :: Monad m => Int -> m a -> m [a]+replicate = M.replicateM++lift :: Monad m => (a -> r) -> m a -> m r+lift = M.liftM++lift2 ::+   Monad m => (a -> b -> r) -> m a -> m b -> m r+lift2 = M.liftM2++lift3 ::+   Monad m => (a -> b -> c -> r) -> m a -> m b -> m c -> m r+lift3 = M.liftM3++lift4 ::+   Monad m =>+   (a -> b -> c -> d -> r) -> m a -> m b -> m c -> m d -> m r+lift4 = M.liftM4++lift5 ::+   Monad m =>+   (a -> b -> c -> d -> e -> r) ->+   m a -> m b -> m c -> m d -> m e -> m r+lift5 = M.liftM5++{-+Add functions with restricted types?+Shall their element types be monoids?+Should we add these functions to a Foldable.HT module+in order to save the underscore?++(>>)+mapM_+zipWithM_+sequence_+...+-}
src/Data/List/HT.hs view
@@ -13,6 +13,8 @@    L.breakAfter,    L.segmentAfter,    L.segmentBefore,+   L.segmentAfterMaybe,+   L.segmentBeforeMaybe,    L.removeEach,    L.splitEverywhere,    --  * inspect ends of a list
src/Data/List/HT/Private.hs view
@@ -1,11 +1,11 @@ module Data.List.HT.Private where  import Data.List  as List  (find, transpose, unfoldr, isPrefixOf,-                            findIndices, foldl', )+                            findIndices, foldl', mapAccumL, ) import Data.Maybe as Maybe (fromMaybe, catMaybes, ) import Data.Maybe.HT       (toMaybe, ) import Control.Monad       (guard, msum, )-import Data.Tuple.HT       (mapPair, mapFst, mapSnd, forcePair, )+import Data.Tuple.HT       (mapPair, mapFst, mapSnd, forcePair, swap, )  import qualified Data.List.Key.Private   as Key import qualified Data.List.Match.Private as Match@@ -198,10 +198,10 @@ Keep the terminator. There is always a list for the part after the last terminator. It may be empty.+See package @non-empty@ for more precise result type. -} segmentAfter :: (a -> Bool) -> [a] -> [[a]] segmentAfter p =---   foldr (\ x ~yt@(y:ys) -> if p x then [x]:yt else (x:y):ys) [[]]    uncurry (:) .    foldr       (\x ~(y,ys) ->@@ -209,6 +209,10 @@          if p x then ([],y:ys) else (y,ys))       ([],[]) +segmentAfter' :: (a -> Bool) -> [a] -> [[a]]+segmentAfter' p =+   foldr (\ x ~yt@(y:ys) -> if p x then [x]:yt else (x:y):ys) [[]]+ propSegmentAfterConcat :: Eq a => (a -> Bool) -> [a] -> Bool propSegmentAfterConcat p xs =    concat (segmentAfter p xs) == xs@@ -237,6 +241,7 @@ Keep these characters. There is always a list for the part before the first leading character. It may be empty.+See package @non-empty@ for more precise result type. -} segmentBefore :: (a -> Bool) -> [a] -> [[a]] segmentBefore p =@@ -295,6 +300,35 @@ propSegmentBeforeGroupBy1 :: Eq a => (a -> Bool) -> [a] -> Bool propSegmentBeforeGroupBy1 p xs =    segmentBefore p xs == segmentBefore'' p xs+++{- |+> Data.List.HT Data.Char> segmentBeforeMaybe (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---"+> ("123",[('A',"5345"),('B',"---")])+-}+segmentBeforeMaybe ::+   (a -> Maybe b) ->+   [a] -> ([a], [(b, [a])])+segmentBeforeMaybe f =+   forcePair .+   foldr+      (\ x ~(y,ys) ->+         case f x of+            Just b -> ([],(b,y):ys)+            Nothing -> (x:y,ys))+      ([],[])++{- |+> Data.List.HT Data.Char> segmentAfterMaybe (\c -> toMaybe (isLetter c) (toUpper c)) "123a5345b---"+> ([("123",'A'),("5345",'B')],"---")+-}+segmentAfterMaybe ::+   (a -> Maybe b) ->+   [a] -> ([([a], b)], [a])+segmentAfterMaybe f =+   swap .+   uncurry (mapAccumL (\as0 (b,as1) -> (as1, (as0,b)))) .+   segmentBeforeMaybe f   -- cf. Matroid.hs
src/Data/Monoid/HT.hs view
@@ -1,9 +1,9 @@-module Data.Monoid.HT (cycle, (<>), ) where+module Data.Monoid.HT (cycle, (<>), when, ) where -import Data.Monoid (Monoid, mappend, )+import Data.Monoid (Monoid, mappend, mempty, ) import Data.Function (fix, ) -import Prelude ()+import Prelude (Bool)   {- |@@ -17,7 +17,11 @@ infixr 6 <>  {- |-Infix synonym for 'mappend.+Infix synonym for 'mappend'. -} (<>) :: Monoid m => m -> m -> m (<>) = mappend+++when :: Monoid m => Bool -> m -> m+when b m = if b then m else mempty
utility-ht.cabal view
@@ -1,5 +1,5 @@ Name:             utility-ht-Version:          0.0.9+Version:          0.0.10 License:          BSD3 License-File:     LICENSE Author:           Henning Thielemann <haskell@henning-thielemann.de>@@ -44,7 +44,7 @@ Source-Repository this   type:     darcs   location: http://code.haskell.org/~thielema/utility/-  tag:      0.0.9+  tag:      0.0.10  Library   Build-Depends: