Data.Monoid.Instances.Stateful

monoid-subclasses-0.4.3.1: Subclasses of Monoid

Safe Haskell | Safe
Language | Haskell2010

Data.Monoid.Instances.Stateful

Description

This module defines the monoid transformer data type `Stateful`.

    > let s = setState [4] $ pure "data" :: Stateful [Int] String
    > s
    Stateful ("data",[4])
    > factors s
    [Stateful ("d",[]),Stateful ("a",[]),Stateful ("t",[]),Stateful ("a",[]),Stateful ("",[4])]

Synopsis

- newtype Stateful a b = Stateful (b, a)
- extract :: Stateful a b -> b
- state :: Stateful a b -> a
- setState :: a -> Stateful a b -> Stateful a b

# Documentation

newtype Stateful a b #

``Stateful` a b` is a wrapper around the `Monoid` `b` that carries the state `a` along. The state type `a` must be a monoid as well if `Stateful` is to be of any use. In the `FactorialMonoid` and `TextualMonoid` class instances, the monoid `b` has the priority and the state `a` is left for the end.

Constructors

Stateful (b, a) |

Instances

Functor (Stateful a) # |
Methods fmap :: (a -> b) -> Stateful a a -> Stateful a b # (<$) :: a -> Stateful a b -> Stateful a a #
Monoid a => Applicative (Stateful a) # |
Methods pure :: a -> Stateful a a # (<*>) :: Stateful a (a -> b) -> Stateful a a -> Stateful a b # (*>) :: Stateful a a -> Stateful a b -> Stateful a b # (<*) :: Stateful a a -> Stateful a b -> Stateful a a #
(Eq a, Eq b) => Eq (Stateful a b) # |
Methods (==) :: Stateful a b -> Stateful a b -> Bool # (/=) :: Stateful a b -> Stateful a b -> Bool #
(Ord a, Ord b) => Ord (Stateful a b) # |
Methods compare :: Stateful a b -> Stateful a b -> Ordering # (<) :: Stateful a b -> Stateful a b -> Bool # (<=) :: Stateful a b -> Stateful a b -> Bool # (>) :: Stateful a b -> Stateful a b -> Bool # (>=) :: Stateful a b -> Stateful a b -> Bool # max :: Stateful a b -> Stateful a b -> Stateful a b # min :: Stateful a b -> Stateful a b -> Stateful a b #
(Show a, Show b) => Show (Stateful a b) # |
Methods showsPrec :: Int -> Stateful a b -> ShowS # show :: Stateful a b -> String # showList :: [Stateful a b] -> ShowS #
(Monoid a, IsString b) => IsString (Stateful a b) # |
Methods fromString :: String -> Stateful a b #
(Monoid a, Monoid b) => Monoid (Stateful a b) # |
Methods mempty :: Stateful a b # mappend :: Stateful a b -> Stateful a b -> Stateful a b # mconcat :: [Stateful a b] -> Stateful a b #
(PositiveMonoid a, PositiveMonoid b) => PositiveMonoid (Stateful a b) # |
(MonoidNull a, MonoidNull b) => MonoidNull (Stateful a b) # |
Methods null :: Stateful a b -> Bool #
(StableFactorialMonoid a, StableFactorialMonoid b) => StableFactorialMonoid (Stateful a b) # |
(FactorialMonoid a, FactorialMonoid b) => FactorialMonoid (Stateful a b) # |
Methods factors :: Stateful a b -> [Stateful a b] # primePrefix :: Stateful a b -> Stateful a b # primeSuffix :: Stateful a b -> Stateful a b # splitPrimePrefix :: Stateful a b -> Maybe (Stateful a b, Stateful a b) # splitPrimeSuffix :: Stateful a b -> Maybe (Stateful a b, Stateful a b) # inits :: Stateful a b -> [Stateful a b] # tails :: Stateful a b -> [Stateful a b] # foldl :: (a -> Stateful a b -> a) -> a -> Stateful a b -> a # foldl' :: (a -> Stateful a b -> a) -> a -> Stateful a b -> a # foldr :: (Stateful a b -> a -> a) -> a -> Stateful a b -> a # length :: Stateful a b -> Int # foldMap :: Monoid n => (Stateful a b -> n) -> Stateful a b -> n # span :: (Stateful a b -> Bool) -> Stateful a b -> (Stateful a b, Stateful a b) # break :: (Stateful a b -> Bool) -> Stateful a b -> (Stateful a b, Stateful a b) # split :: (Stateful a b -> Bool) -> Stateful a b -> [Stateful a b] # takeWhile :: (Stateful a b -> Bool) -> Stateful a b -> Stateful a b # dropWhile :: (Stateful a b -> Bool) -> Stateful a b -> Stateful a b # spanMaybe :: s -> (s -> Stateful a b -> Maybe s) -> Stateful a b -> (Stateful a b, Stateful a b, s) # spanMaybe' :: s -> (s -> Stateful a b -> Maybe s) -> Stateful a b -> (Stateful a b, Stateful a b, s) # splitAt :: Int -> Stateful a b -> (Stateful a b, Stateful a b) # drop :: Int -> Stateful a b -> Stateful a b # take :: Int -> Stateful a b -> Stateful a b # reverse :: Stateful a b -> Stateful a b #
(RightGCDMonoid a, RightGCDMonoid b) => RightGCDMonoid (Stateful a b) # |
Methods commonSuffix :: Stateful a b -> Stateful a b -> Stateful a b # stripCommonSuffix :: Stateful a b -> Stateful a b -> (Stateful a b, Stateful a b, Stateful a b) #
(LeftGCDMonoid a, LeftGCDMonoid b) => LeftGCDMonoid (Stateful a b) # |
Methods commonPrefix :: Stateful a b -> Stateful a b -> Stateful a b # stripCommonPrefix :: Stateful a b -> Stateful a b -> (Stateful a b, Stateful a b, Stateful a b) #
(RightReductiveMonoid a, RightReductiveMonoid b) => RightReductiveMonoid (Stateful a b) # |
Methods isSuffixOf :: Stateful a b -> Stateful a b -> Bool # stripSuffix :: Stateful a b -> Stateful a b -> Maybe (Stateful a b) #
(LeftReductiveMonoid a, LeftReductiveMonoid b) => LeftReductiveMonoid (Stateful a b) # |
Methods isPrefixOf :: Stateful a b -> Stateful a b -> Bool # stripPrefix :: Stateful a b -> Stateful a b -> Maybe (Stateful a b) #
(LeftGCDMonoid a, FactorialMonoid a, TextualMonoid b) => TextualMonoid (Stateful a b) # |
Methods fromText :: Text -> Stateful a b # singleton :: Char -> Stateful a b # splitCharacterPrefix :: Stateful a b -> Maybe (Char, Stateful a b) # characterPrefix :: Stateful a b -> Maybe Char # map :: (Char -> Char) -> Stateful a b -> Stateful a b # concatMap :: (Char -> Stateful a b) -> Stateful a b -> Stateful a b # toString :: (Stateful a b -> String) -> Stateful a b -> String # any :: (Char -> Bool) -> Stateful a b -> Bool # all :: (Char -> Bool) -> Stateful a b -> Bool # foldl :: (a -> Stateful a b -> a) -> (a -> Char -> a) -> a -> Stateful a b -> a # foldl' :: (a -> Stateful a b -> a) -> (a -> Char -> a) -> a -> Stateful a b -> a # foldr :: (Stateful a b -> a -> a) -> (Char -> a -> a) -> a -> Stateful a b -> a # scanl :: (Char -> Char -> Char) -> Char -> Stateful a b -> Stateful a b # scanl1 :: (Char -> Char -> Char) -> Stateful a b -> Stateful a b # scanr :: (Char -> Char -> Char) -> Char -> Stateful a b -> Stateful a b # scanr1 :: (Char -> Char -> Char) -> Stateful a b -> Stateful a b # mapAccumL :: (a -> Char -> (a, Char)) -> a -> Stateful a b -> (a, Stateful a b) # mapAccumR :: (a -> Char -> (a, Char)) -> a -> Stateful a b -> (a, Stateful a b) # takeWhile :: (Stateful a b -> Bool) -> (Char -> Bool) -> Stateful a b -> Stateful a b # dropWhile :: (Stateful a b -> Bool) -> (Char -> Bool) -> Stateful a b -> Stateful a b # break :: (Stateful a b -> Bool) -> (Char -> Bool) -> Stateful a b -> (Stateful a b, Stateful a b) # span :: (Stateful a b -> Bool) -> (Char -> Bool) -> Stateful a b -> (Stateful a b, Stateful a b) # spanMaybe :: s -> (s -> Stateful a b -> Maybe s) -> (s -> Char -> Maybe s) -> Stateful a b -> (Stateful a b, Stateful a b, s) # spanMaybe' :: s -> (s -> Stateful a b -> Maybe s) -> (s -> Char -> Maybe s) -> Stateful a b -> (Stateful a b, Stateful a b, s) # split :: (Char -> Bool) -> Stateful a b -> [Stateful a b] # find :: (Char -> Bool) -> Stateful a b -> Maybe Char # elem :: Char -> Stateful a b -> Bool # foldl_ :: (a -> Char -> a) -> a -> Stateful a b -> a # foldl_' :: (a -> Char -> a) -> a -> Stateful a b -> a # foldr_ :: (Char -> a -> a) -> a -> Stateful a b -> a # takeWhile_ :: Bool -> (Char -> Bool) -> Stateful a b -> Stateful a b # dropWhile_ :: Bool -> (Char -> Bool) -> Stateful a b -> Stateful a b # break_ :: Bool -> (Char -> Bool) -> Stateful a b -> (Stateful a b, Stateful a b) # span_ :: Bool -> (Char -> Bool) -> Stateful a b -> (Stateful a b, Stateful a b) # spanMaybe_ :: s -> (s -> Char -> Maybe s) -> Stateful a b -> (Stateful a b, Stateful a b, s) # spanMaybe_' :: s -> (s -> Char -> Maybe s) -> Stateful a b -> (Stateful a b, Stateful a b, s) #

extract :: Stateful a b -> b #

state :: Stateful a b -> a #

setState :: a -> Stateful a b -> Stateful a b #