subG-0.4.2.0: Some extension to the Foldable and Monoid classes.
Copyright(c) OleksandrZhabenko 2020
LicenseMIT
Maintainerolexandr543@yahoo.com
StabilityExperimental
Safe HaskellSafe-Inferred
LanguageHaskell2010

Data.SubG

Description

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.

Synopsis

Documentation

class (Foldable t, Eq a, Eq (t a)) => InsertLeft t a where Source #

Some extension to the Foldable and Monoid classes.

Methods

(%@) :: a -> t a -> t a infixr 1 Source #

(%^) :: t a -> t (t a) -> t (t a) infixr 1 Source #

Instances

Instances details
Eq a => InsertLeft [] a Source # 
Instance details

Defined in Data.SubG

Methods

(%@) :: a -> [a] -> [a] Source #

(%^) :: [a] -> [[a]] -> [[a]] Source #

subG :: (InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a -> t a -> t (t a) Source #

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.

takeG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

takeFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

reverseTakeG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

reverseTakeFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

dropG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

dropFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

reverseDropG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

reverseDropFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a Source #

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.

takeWhile :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a Source #

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 Source #

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) Source #

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.

splitAtG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> (t a, t a) Source #

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.

splitAtEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> (t a, t a) Source #

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.

preAppend :: (InsertLeft t a, Monoid (t (t a))) => t a -> t (t a) -> t (t a) -> t (t a) Source #

Prepends and appends the given two first arguments to the third one.

safeHeadG :: Foldable t => t a -> Maybe a Source #

If a structure is empty, just returns Nothing.

safeTailG :: (InsertLeft t a, Monoid (t a)) => t a -> t a Source #

If the structure is empty, just returns itself. Uses strict variant of the foldl, so is strict and the data must be finite.

safeInitG :: (InsertLeft t a, Monoid (t a)) => t a -> t a Source #

If the structure is empty, just returns itself.

safeLastG :: (InsertLeft t a, Monoid (t a)) => t a -> Maybe a Source #

If the structure is empty, just returns Nothing.

mapG :: (InsertLeft t b, Monoid (t b)) => (a -> b) -> t a -> t b Source #

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. Acts similarly to the map function from Prelude.

filterG :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a Source #

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. Acts similarly to filter function from Prelude.

partitionG :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> (t a, t a) Source #

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. Acts similarly to partition function from Data.List. Practically is a rewritten for more general variants function partition from https://hackage.haskell.org/package/base-4.14.0.0/docs/src/Data.OldList.html#partition