packages feed

subG 0.2.1.0 → 0.3.0.0

raw patch · 3 files changed

+67/−2 lines, 3 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.MinMax3Plus: minMax23 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a), (a, a, a))
+ Data.MinMax3Plus: minMax32 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a, a), (a, a))
+ Data.MinMax3Plus: minMax33 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a, a), (a, a, a))

Files

CHANGELOG.md view
@@ -22,3 +22,7 @@ * Second version revised A. Fixed issues with the ambiguous names in the further reverse dependencies on the package. Now the ambiguous functions have in their names suffix G (it means 'generalization'). Added a new function splitAtEndG to the Data.SubG module. Fixed issues with multiple search minimum and maximum elements functions in the module Data.MinMax. Allowed equal elements in the structures so they are now general. Some documentation improvements.++## 0.3.0.0 -- 2020-11-18++* Third version. Added a new module Data.MinMax3Plus with additional functions.
+ Data/MinMax3Plus.hs view
@@ -0,0 +1,61 @@+-- |+-- Module      :  Data.MinMax3Plus+-- Copyright   :  (c) OleksandrZhabenko 2020+-- License     :  MIT+-- Stability   :  Experimental+-- Maintainer  :  olexandr543@yahoo.com+--+-- Functions to find both minimum and maximum elements of the 'F.Foldable' structure of the 'Ord'ered elements.++module Data.MinMax3Plus where++import Prelude hiding (takeWhile,dropWhile,span)+import Data.Maybe (fromJust)+import Data.SubG+import qualified Data.Foldable as F+import qualified Data.List as L (sort)++-- | Given a finite structure with at least 5 elements returns a tuple with two minimum elements+-- and three maximum elements. If the structure has less elements, returns 'Nothing'.+-- Uses just three passes through the structure, so may be more efficient than some other approaches.+minMax23 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a,a), (a,a,a))+minMax23 xs+ | F.length xs < 5 = Nothing+ | otherwise = Just . F.foldr f ((n,p),(q,r,s)) $ str1+      where x = fromJust . safeHeadG $ xs+            (str1,str2) = splitAtEndG 5 xs+            [n,p,q,r,s] = L.sort . F.toList $ str2+            f z ((x,y),(t,w,u))+              | z < y = if z > x then ((x,z),(t,w,u)) else ((z,x),(t,w,u))+              | z > t = if z < w then ((x,y),(z,w,u)) else if z < u then ((x,y),(w,z,u)) else ((x,y),(t,w,u))+              | otherwise = ((x,y),(t,w,u))++-- | Given a finite structure with at least 5 elements returns a tuple with three minimum elements+-- and two maximum elements. If the structure has less elements, returns 'Nothing'.+-- Uses just three passes through the structure, so may be more efficient than some other approaches.+minMax32 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a,a,a), (a,a))+minMax32 xs+ | F.length xs < 5 = Nothing+ | otherwise = Just . F.foldr f ((n,m,p),(q,r)) $ str1+      where x = fromJust . safeHeadG $ xs+            (str1,str2) = splitAtEndG 5 xs+            [n,m,p,q,r] = L.sort . F.toList $ str2+            f z ((x,y,u),(t,w))+              | z < u = if z > y then ((x,y,z),(t,w)) else if z > x then ((x,z,y),(t,w)) else ((z,x,y),(t,w))+              | z > t = if z < w then ((x,y,u),(z,w)) else ((x,y,u),(w,z))+              | otherwise = ((x,y,u),(t,w))++-- | Given a finite structure with at least 6 elements returns a tuple with three minimum elements+-- and three maximum elements. If the structure has less elements, returns 'Nothing'.+-- Uses just three passes through the structure, so may be more efficient than some other approaches.+minMax33 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a,a,a), (a,a,a))+minMax33 xs+ | F.length xs < 6 = Nothing+ | otherwise = Just . F.foldr f ((n,m,p),(q,r,s)) $ str1+      where x = fromJust . safeHeadG $ xs+            (str1,str2) = splitAtEndG 6 xs+            [n,m,p,q,r,s] = L.sort . F.toList $ str2+            f z ((x,y,u),(t,w,k))+              | z < u = if z > y then ((x,y,z),(t,w,k)) else if z > x then ((x,z,y),(t,w,k)) else ((z,x,y),(t,w,k))+              | z > t = if z < w then ((x,y,u),(z,w,k)) else if z < k then ((x,y,u),(w,z,k)) else ((x,y,u),(w,k,z))+              | otherwise = ((x,y,u),(t,w,k))
subG.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/  name:                subG-version:             0.2.1.0+version:             0.3.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+  exposed-modules:     Data.SubG, Data.MinMax, Data.MinMax3Plus   -- other-modules:   other-extensions:    MultiParamTypeClasses, FlexibleInstances   build-depends:       base >=4.8 && <4.15