fmlist-0.9.2: FoldMap lists

Copyright | (c) Sjoerd Visscher 2009
License | BSD-style (see the file LICENSE)
Maintainer | sjoerd@w3future.com
Stability | experimental
Portability | portable
Safe Haskell | Safe
Language | Haskell98

Data.FMList

Contents

- Construction
- Basic functions
- Folding
- Unfolding

Description

FoldMap lists: lists represented by their `foldMap` function.

Examples:

    -- A right-infinite list
    c = 1 `cons` c

    -- A left-infinite list
    d = d `snoc` 2

    -- A middle-infinite list ??
    e = c `append` d

    *> head e
    1
    *> last e
    2

Synopsis

- newtype FMList a = FM {
  - unFM :: forall m. Monoid m => (a -> m) -> m
  }
- transform :: (forall m. Monoid m => (a -> m) -> b -> m) -> FMList b -> FMList a
- empty :: Alternative f => f a
- singleton :: a -> FMList a
- cons :: a -> FMList a -> FMList a
- snoc :: FMList a -> a -> FMList a
- pair :: a -> a -> FMList a
- append :: FMList a -> FMList a -> FMList a
- fromList :: [a] -> FMList a
- fromFoldable :: Foldable f => f a -> FMList a
- null :: FMList a -> Bool
- length :: FMList a -> Int
- genericLength :: Num b => FMList a -> b
- head :: FMList a -> a
- tail :: FMList a -> FMList a
- last :: FMList a -> a
- init :: FMList a -> FMList a
- reverse :: FMList a -> FMList a
- toList :: Foldable t => t a -> [a]
- flatten :: Foldable t => FMList (t a) -> FMList a
- foldMapA :: (Foldable t, Applicative f, Monoid m) => (a -> f m) -> t a -> f m
- filter :: (a -> Bool) -> FMList a -> FMList a
- take :: (Ord n, Num n) => n -> FMList a -> FMList a
- drop :: (Ord n, Num n) => n -> FMList a -> FMList a
- takeWhile :: (a -> Bool) -> FMList a -> FMList a
- dropWhile :: (a -> Bool) -> FMList a -> FMList a
- zip :: FMList a -> FMList b -> FMList (a, b)
- zipWith :: (a -> b -> c) -> FMList a -> FMList b -> FMList c
- iterate :: (a -> a) -> a -> FMList a
- repeat :: a -> FMList a
- cycle :: FMList a -> FMList a
- unfold :: (b -> FMList (Either b a)) -> b -> FMList a
- unfoldr :: (b -> Maybe (a, b)) -> b -> FMList a

# Documentation

newtype FMList a Source #

`FMList` is a `foldMap` function wrapped up in a newtype.

Constructors

FM |

Fields

- unFM :: forall m. Monoid m => (a -> m) -> m

Instances

Monad FMList Source # |
Instance details Defined in Data.FMList Methods (>>=) :: FMList a -> (a -> FMList b) -> FMList b Source # (>>) :: FMList a -> FMList b -> FMList b Source # return :: a -> FMList a Source # fail :: String -> FMList a Source #
Functor FMList Source # |
Instance details Defined in Data.FMList Methods fmap :: (a -> b) -> FMList a -> FMList b Source # (<$) :: a -> FMList b -> FMList a Source #
Applicative FMList Source # |
Instance details Defined in Data.FMList Methods pure :: a -> FMList a Source # (<*>) :: FMList (a -> b) -> FMList a -> FMList b Source # liftA2 :: (a -> b -> c) -> FMList a -> FMList b -> FMList c Source # (*>) :: FMList a -> FMList b -> FMList b Source # (<*) :: FMList a -> FMList b -> FMList a Source #
Foldable FMList Source # |

Instance details

Defined in Data.FMList

Methods

fold :: Monoid m => FMList m -> m Source #

foldMap :: Monoid m => (a -> m) -> FMList a -> m Source #

foldr :: (a -> b -> b) -> b -> FMList a -> b Source #

foldr' :: (a -> b -> b) -> b -> FMList a -> b Source #

foldl :: (b -> a -> b) -> b -> FMList a -> b Source #

foldl' :: (b -> a -> b) -> b -> FMList a -> b Source #

foldr1 :: (a -> a -> a) -> FMList a -> a Source #

foldl1 :: (a -> a -> a) -> FMList a -> a Source #

toList :: FMList a -> [a] Source #

null :: FMList a -> Bool Source #

length :: FMList a -> Int Source #

elem :: Eq a => a -> FMList a -> Bool Source #

maximum :: Ord a => FMList a -> a Source #

minimum :: Ord a => FMList a -> a Source #

sum :: Num a => FMList a -> a Source #

product :: Num a => FMList a -> a Source #

Traversable FMList Source # |
Instance details Defined in Data.FMList Methods traverse :: Applicative f => (a -> f b) -> FMList a -> f (FMList b) Source # sequenceA :: Applicative f => FMList (f a) -> f (FMList a) Source # mapM :: Monad m => (a -> m b) -> FMList a -> m (FMList b) Source # sequence :: Monad m => FMList (m a) -> m (FMList a) Source #
Alternative FMList Source # |
Instance details Defined in Data.FMList Methods empty :: FMList a Source # (<|>) :: FMList a -> FMList a -> FMList a Source # some :: FMList a -> FMList [a] Source # many :: FMList a -> FMList [a] Source #
MonadPlus FMList Source # |
Instance details Defined in Data.FMList Methods mzero :: FMList a Source # mplus :: FMList a -> FMList a -> FMList a Source #
Show a => Show (FMList a) Source # |
Instance details Defined in Data.FMList Methods showsPrec :: Int -> FMList a -> ShowS Source # show :: FMList a -> String Source # showList :: [FMList a] -> ShowS Source #
Semigroup (FMList a) Source # |
Instance details Defined in Data.FMList Methods (<>) :: FMList a -> FMList a -> FMList a Source # sconcat :: NonEmpty (FMList a) -> FMList a Source # stimes :: Integral b => b -> FMList a -> FMList a Source #
Monoid (FMList a) Source # |
Instance details Defined in Data.FMList Methods mempty :: FMList a Source # mappend :: FMList a -> FMList a -> FMList a Source # mconcat :: [FMList a] -> FMList a Source #

transform :: (forall m. Monoid m => (a -> m) -> b -> m) -> FMList b -> FMList a Source #

The function `transform` transforms a list by changing the map function that is passed to `foldMap`.

It has the following property:

    transform a . transform b = transform (b . a)

For example:

-       m >>= g

-     = flatten (fmap g m)

-     = flatten . fmap g $ m

-     = transform foldMap . transform (. g) $ m

-     = transform ((. g) . foldMap) m

-     = transform (\f -> foldMap f . g) m

# Construction

empty :: Alternative f => f a Source #

The identity of `<|>`

singleton :: a -> FMList a Source #

cons :: a -> FMList a -> FMList a Source #

snoc :: FMList a -> a -> FMList a Source #

pair :: a -> a -> FMList a Source #

append :: FMList a -> FMList a -> FMList a Source #

fromList :: [a] -> FMList a Source #

fromFoldable :: Foldable f => f a -> FMList a Source #

# Basic functions

null :: FMList a -> Bool Source #

length :: FMList a -> Int Source #

genericLength :: Num b => FMList a -> b Source #

head :: FMList a -> a Source #

tail :: FMList a -> FMList a Source #

last :: FMList a -> a Source #

init :: FMList a -> FMList a Source #

reverse :: FMList a -> FMList a Source #

# Folding

toList :: Foldable t => t a -> [a] Source #

List of elements of a structure, from left to right.

flatten :: Foldable t => FMList (t a) -> FMList a Source #

foldMapA :: (Foldable t, Applicative f, Monoid m) => (a -> f m) -> t a -> f m Source #

Map each element of a structure to an action, evaluate these actions from left to right, and concat the monoid results.

filter :: (a -> Bool) -> FMList a -> FMList a Source #

take :: (Ord n, Num n) => n -> FMList a -> FMList a Source #

drop :: (Ord n, Num n) => n -> FMList a -> FMList a Source #

takeWhile :: (a -> Bool) -> FMList a -> FMList a Source #

dropWhile :: (a -> Bool) -> FMList a -> FMList a Source #

zip :: FMList a -> FMList b -> FMList (a, b) Source #

zipWith :: (a -> b -> c) -> FMList a -> FMList b -> FMList c Source #

# Unfolding

iterate :: (a -> a) -> a -> FMList a Source #

repeat :: a -> FMList a Source #

`repeat` buids an infinite list of a single value. While infinite, the result is still accessible from both the start and end.

cycle :: FMList a -> FMList a Source #

`cycle` repeats a list to create an infinite list. It is also accessible from the end, where `last (cycle l)` equals `last l`.

unfold :: (b -> FMList (Either b a)) -> b -> FMList a Source #

`unfold` builds a list from a seed value. The function takes the seed and returns an `FMList` of values. If the value is `Right` `a`, then `a` is appended to the result, and if the value is `Left` `b`, then `b` is used as seed value in a recursive call.

A simple use of `unfold` (simulating unfoldl):

    *> unfold (\b -> if b == 0 then empty else Left (b-1) `pair` Right b) 10
    fromList [1,2,3,4,5,6,7,8,9,10]

unfoldr :: (b -> Maybe (a, b)) -> b -> FMList a Source #

`unfoldr` builds an `FMList` from a seed value from left to right. The function takes the element and returns `Nothing` if it is done producing the list or returns `Just` `(a,b)`, in which case, `a` is a appended to the result and `b` is used as the next seed value in a recursive call.

A simple use of `unfoldr`:

    *> unfoldr (\b -> if b == 0 then Nothing else Just (b, b-1)) 10
    fromList [10,9,8,7,6,5,4,3,2,1]