Copyright | (c) OleksandrZhabenko 2020 |
---|---|

License | MIT |

Maintainer | olexandr543@yahoo.com |

Stability | Experimental |

Safe Haskell | Safe-Inferred |

Language | Haskell2010 |

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

- class (Foldable t, Eq a, Eq (t a)) => InsertLeft t a where
- subG :: (InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a -> t a -> t (t a)
- takeG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- takeFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- reverseTakeG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- reverseTakeFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- dropG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- dropFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- reverseDropG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- reverseDropFromEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> t a
- takeWhile :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a
- dropWhile :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a
- span :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> (t a, t a)
- splitAtG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> (t a, t a)
- splitAtEndG :: (Integral b, InsertLeft t a, Monoid (t a)) => b -> t a -> (t a, t a)
- preAppend :: (InsertLeft t a, Monoid (t (t a))) => t a -> t (t a) -> t (t a) -> t (t a)
- safeHeadG :: Foldable t => t a -> Maybe a
- safeTailG :: (InsertLeft t a, Monoid (t a)) => t a -> t a
- safeInitG :: (InsertLeft t a, Monoid (t a)) => t a -> t a
- safeLastG :: (InsertLeft t a, Monoid (t a)) => t a -> Maybe a
- mapG :: (InsertLeft t b, Monoid (t b)) => (a -> b) -> t a -> t b
- filterG :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> t a
- partitionG :: (InsertLeft t a, Monoid (t a)) => (a -> Bool) -> t a -> (t a, t a)

# Documentation

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.

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