packages feed

ixset-typed-conversions 0.1.0.1 → 0.1.1.0

raw patch · 3 files changed

+32/−2 lines, 3 filesdep +freePVP ok

version bump matches the API change (PVP)

Dependencies added: free

API changes (from Hackage documentation)

+ Data.IxSet.Typed.Conversions: toAscCofreeList :: (Ord b, IsIndexOf ix ixs) => (ix -> c) -> (a -> c) -> (a -> b) -> IxSet ixs a -> [Cofree [] c]
+ Data.IxSet.Typed.Conversions: toAscCofreeListM :: (Ord b, IsIndexOf ix ixs, Monad m) => (ix -> m c) -> (a -> c) -> (a -> b) -> IxSet ixs a -> m [Cofree [] c]
+ Data.IxSet.Typed.Conversions: toDescCofreeList :: (Ord b, IsIndexOf ix ixs) => (ix -> c) -> (a -> c) -> (a -> b) -> IxSet ixs a -> [Cofree [] c]
+ Data.IxSet.Typed.Conversions: toDescCofreeListM :: (Ord b, IsIndexOf ix ixs, Monad m) => (ix -> m c) -> (a -> c) -> (a -> b) -> IxSet ixs a -> m [Cofree [] c]

Files

ChangeLog.md view
@@ -1,5 +1,9 @@ # Changelog for ixset-typed-conversions +## (v0.1.1.0)++* Add cofree conversions.+ ## (v0.1.0.0) -Add conversion functions from `IxSet` to `HashMap` and `Zipper []`.+* Add conversion functions from `IxSet` to `HashMap` and `Zipper []`.
ixset-typed-conversions.cabal view
@@ -5,7 +5,7 @@ -- see: https://github.com/sol/hpack  name:           ixset-typed-conversions-version:        0.1.0.1+version:        0.1.1.0 synopsis:       Conversions from ixset-typed to other containers. description:    Conversions from ixset-typed to other containers; HashMaps, zippers. category:       Data Structures@@ -34,6 +34,7 @@   build-depends:       base >=4.7 && <5     , exceptions+    , free     , hashable     , ixset-typed     , unordered-containers
src/Data/IxSet/Typed/Conversions.hs view
@@ -12,13 +12,20 @@ , toHashMapByM , toZipperAsc , toZipperDesc+, toAscCofreeList+, toAscCofreeListM+, toDescCofreeList+, toDescCofreeListM ) where +import           Control.Applicative+import           Control.Comonad.Cofree import           Control.Comonad.Zipper.Extra import           Control.Monad import           Control.Monad.Catch import           Data.Hashable import qualified Data.HashMap.Strict          as HM+import qualified Data.List                    as L import           Data.IxSet.Typed             as Ix import           Data.Proxy @@ -43,3 +50,21 @@ -- | Convert an `IxSet` to a `Zipper` by descending sort on an index. toZipperDesc :: forall proxy ix ixs a m. (IsIndexOf ix ixs, MonadThrow m) => proxy ix -> IxSet ixs a -> m (Zipper [] a) toZipperDesc _ = zipper' . Ix.toDescList (Proxy :: Proxy ix)++-- | Convert an `IxSet` to a list of `Cofree` by grouping on one of its indices. The result will be sorted in ascending+-- order on the index. The elements will be sorted according to the `Ord` instance on b.+toAscCofreeList :: (Ord b, Ix.IsIndexOf ix ixs) => (ix -> c) -> (a -> c) -> (a -> b) -> Ix.IxSet ixs a -> [Cofree [] c]+toAscCofreeList f g h xs = flip map (Ix.groupAscBy xs) $ \(x, as) -> f x :< map ((:< []) . g) (L.sortOn h as)++-- | Monadic version of `toAscCofreeList`.+toAscCofreeListM :: (Ord b, Ix.IsIndexOf ix ixs, Monad m) => (ix -> m c) -> (a -> c) -> (a -> b) -> Ix.IxSet ixs a -> m [Cofree [] c]+toAscCofreeListM f g h xs = forM (Ix.groupAscBy xs) $ \(x, as) -> liftA2 (:<) (f x) (return $ map ((:< []) . g) (L.sortOn h as))++---- | Convert an `IxSet` to a list of `Cofree` by grouping on one of its indices. The result will be sorted in descending+-- order on the index. The elements will be sorted according to the `Ord` instance on b.+toDescCofreeList :: (Ord b, Ix.IsIndexOf ix ixs) => (ix -> c) -> (a -> c) -> (a -> b) -> Ix.IxSet ixs a -> [Cofree [] c]+toDescCofreeList f g h xs = flip map (Ix.groupDescBy xs) $ \(x, as) -> f x :< map ((:< []) . g) (L.sortOn h as)++-- | Monadic version of `toDescCofreeList`.+toDescCofreeListM :: (Ord b, Ix.IsIndexOf ix ixs, Monad m) => (ix -> m c) -> (a -> c) -> (a -> b) -> Ix.IxSet ixs a -> m [Cofree [] c]+toDescCofreeListM f g h xs = forM (Ix.groupDescBy xs) $ \(x, as) -> liftA2 (:<) (f x) (return $ map ((:< []) . g) (L.sortOn h as))