subG 0.4.2.0 → 0.5.0.0
raw patch · 3 files changed
+43/−2 lines, 3 files
Files
- CHANGELOG.md +4/−0
- Data/SubG/Unfold.hs +37/−0
- subG.cabal +2/−2
CHANGELOG.md view
@@ -39,3 +39,7 @@ ## 0.4.2.0 -- 2020-11-19 * Fourth version revised B. Added two new functions partitionG to the module.++## 0.5.0.0 -- 2021-06-28++* Fifth version. Added a new module Data.SubG.Unfold inspired by: https://www.works-hub.com/learn/number-anamorphisms-aka-unfolds-explained-50e1a by Marty Stumpf.
+ Data/SubG/Unfold.hs view
@@ -0,0 +1,37 @@+-- |+-- Module : Data.SubG.Unfold+-- Copyright : (c) OleksandrZhabenko 2021+-- License : MIT+-- Stability : Experimental+-- Maintainer : olexandr543@yahoo.com+--+-- Generalization of the 'Data.List.unfoldr' for the data type that has 'InsertLeft' and 'Monoid' instances.+-- Inspired by: https://www.works-hub.com/learn/number-anamorphisms-aka-unfolds-explained-50e1a by Marty Stumpf.++module Data.SubG.Unfold (+ unfoldG+ , iterateG+) where++import Data.SubG+import Data.Maybe (isJust, fromJust)+import Data.Monoid++-- | Inspired by: https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.OldList.html#words+-- and: Graham Hutton. A tutorial on the universality and expressiveness of fold. /J. Functional Programming/ 9 (4): 355–372, July 1999.+-- that is available at the URL: https://www.cs.nott.ac.uk/~pszgmh/fold.pdf.+-- Also inspired by: https://www.works-hub.com/learn/number-anamorphisms-aka-unfolds-explained-50e1a by Marty Stumpf.+-- Generalizes the 'Data.List.unfoldr' function not only for lists, but for the data type that has 'InsertLeft' and 'Monoid' instances.+unfoldG :: (InsertLeft t a, Monoid (t a)) => (a -> Maybe (a, a)) -> a -> t a+unfoldG p x+ | isJust (p x) = x %@ unfoldG p (snd . fromJust . p $ x)+ | otherwise = mempty++-- | Inspired by: https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.OldList.html#words+-- and: Graham Hutton. A tutorial on the universality and expressiveness of fold. /J. Functional Programming/ 9 (4): 355–372, July 1999.+-- that is available at the URL: https://www.cs.nott.ac.uk/~pszgmh/fold.pdf.+-- Also inspired by: https://www.works-hub.com/learn/number-anamorphisms-aka-unfolds-explained-50e1a by Marty Stumpf.+-- Generalizes the 'Prelude.iterate' function not only for lists, but for the data type that has 'InsertLeft' and 'Monoid' instances.+iterateG :: (InsertLeft t a, Monoid (t a)) => (a -> a) -> a -> t a+iterateG f = unfoldG (\x -> Just (x, f x))+{-# INLINE iterateG #-}
subG.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/ name: subG-version: 0.4.2.0+version: 0.5.0.0 synopsis: Some extension to the Foldable and Monoid classes. description: Introduces a new class InsertLeft -- the class of types of values that can be inserted from the left to the Foldable structure that is a data that is also the Monoid instance. Also contains some functions to find out both minimum and maximum elements of the finite Foldable structures. homepage: https://hackage.haskell.org/package/subG@@ -17,7 +17,7 @@ cabal-version: >=1.10 library- exposed-modules: Data.SubG, Data.MinMax, Data.MinMax3Plus, Data.MinMax.Preconditions, Data.MinMax3Plus.Preconditions+ exposed-modules: Data.SubG, Data.SubG.Unfold, Data.MinMax, Data.MinMax3Plus, Data.MinMax.Preconditions, Data.MinMax3Plus.Preconditions -- other-modules: other-extensions: MultiParamTypeClasses, FlexibleInstances build-depends: base >=4.8 && <4.15