-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Some extension to the Foldable and Monoid classes. -- -- 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. @package subG @version 0.2.1.0 -- | Some extension to the Foldable and Monoid classes. -- Introduces a new class InsertLeft -- the class of types of -- values that can be inserted from the left to the Foldable -- structure that is simultaneously the data that is also the -- Monoid instance. module Data.SubG -- | Some extension to the Foldable and Monoid classes. class (Foldable t, Eq a, Eq (t a)) => InsertLeft t a (%@) :: InsertLeft t a => a -> t a -> t a (%^) :: InsertLeft t a => t a -> t (t a) -> t (t a) infixr 1 %@ infixr 1 %^ -- | 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. Is similar to the -- words but operates on more general structures an allows more -- control. subG :: (InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a -> t a -> t (t a) -- | Inspired by: 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. Uses strict variant -- of the foldl, so is strict and the data must be finite. takeG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Takes the first -- argument quantity from the right end of the structure preserving the -- order. takeFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Is analogous to the -- taking the specified quantity from the structure and then reversing -- the result. Uses strict variant of the foldl, so is not suitable for -- large amounts of data. reverseTakeG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Takes the specified -- quantity from the right end of the structure and then reverses the -- result. reverseTakeFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Uses strict variant -- of the foldl, so is strict and the data must be finite. dropG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Drops the first -- argument quantity from the right end of the structure and returns the -- result preserving the order. dropFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Is analogous to the -- dropping the specified quantity from the structure and then reversing -- the result. Uses strict variant of the foldl, so is strict and the -- data must be finite. reverseDropG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. Drops the specified -- quantity from the right end of the structure and then reverses the -- result. reverseDropFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a -- | Inspired by: 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. takeWhile :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a -- | Inspired by: 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. dropWhile :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a -- | Inspired by: 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. span :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> (t a, t a) -- | Inspired by: 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. Uses strict variant -- of the foldl, so is strict and the data must be finite. splitAtG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> (t a, t a) -- | Inspired by: 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. Splits the -- structure starting from the end and preserves the order. splitAtEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> (t a, t a) -- | Prepends and appends the given two first arguments to the third one. preAppend :: (InsertLeft t a, Monoid (t (t a))) => t a -> t (t a) -> t (t a) -> t (t a) -- | If a structure is empty, just returns Nothing. safeHeadG :: Foldable t => t a -> Maybe a -- | If the structure is empty, just returns itself. Uses strict variant of -- the foldl, so is strict and the data must be finite. safeTailG :: (InsertLeft t a, Monoid (t a)) => t a -> t a -- | If the structure is empty, just returns itself. safeInitG :: (InsertLeft t a, Monoid (t a)) => t a -> t a -- | If the structure is empty, just returns Nothing. safeLastG :: (InsertLeft t a, Monoid (t a)) => t a -> Maybe a instance GHC.Classes.Eq a => Data.SubG.InsertLeft [] a -- | Functions to find both minimum and maximum elements of the -- Foldable structure of the Ordered elements. module Data.MinMax -- | Returns a pair where the first element is the minimum element from the -- two given ones and the second one is the maximum. If the arguments are -- equal then the tuple contains equal elements. minmaxP :: Ord a => a -> a -> (a, a) -- | A ternary predicate to check whether the third argument lies between -- the first two unequal ones or whether they are all equal. betweenNX :: Ord a => a -> a -> a -> Bool -- | Finds out the minimum and maximum values of the finite structure. If -- the latter one is empty returns Nothing, if all the elements -- are equal (or it has just one) then it returns Just tuple of -- equal elements. minMax :: (Ord a, Foldable t) => t a -> Maybe (a, a) -- | A generalized variant of the minMax where you can specify your -- own comparison function. minMaxBy :: (Ord a, Foldable t) => (a -> a -> Ordering) -> t a -> Maybe (a, a) -- | Given a finite structure with at least 3 elements returns a tuple with -- the two most minimum elements (the first one is less than the second -- one) and the maximum element. If the structure has less elements, -- returns Nothing. Uses just three passes through the structure, -- so may be more efficient than some other approaches. minMax21 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a), a) -- | Given a finite structure with at least 3 elements returns a tuple with -- the minimum element and two maximum elements (the first one is less -- than the second one). If the structure has less elements, returns -- Nothing. Uses just three passes through the structure, so may -- be more efficient than some other approaches. minMax12 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe (a, (a, a)) -- | Given a finite structure with at least 4 elements returns a tuple with -- two 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. minMax22 :: (Ord a, InsertLeft t a, Monoid (t a)) => t a -> Maybe ((a, a), (a, a))