{-# LANGUAGE UndecidableInstances, TypeOperators, FlexibleContexts, MultiParamTypeClasses, FlexibleInstances, TypeFamilies, CPP #-}
#if __GLASGOW_HASKELL__ >= 702 && __GLASGOW_HASKELL__ < 710
{-# LANGUAGE Trustworthy #-}
#endif
module Data.Semigroup.Generator
(
Generator1(..)
, reduce1
, mapReduceWith1
, reduceWith1
) where
import Data.List.NonEmpty (NonEmpty)
import Data.Semigroup.Foldable
import Data.Semigroup.Reducer
import Data.Generator
#if !(MIN_VERSION_base(4,11,0))
import Data.Semigroup (Semigroup(..))
#endif
class Generator c => Generator1 c where
mapReduce1 :: Reducer e m => (Elem c -> e) -> c -> m
mapTo1 :: Reducer e m => (Elem c -> e) -> m -> c -> m
mapFrom1 :: Reducer e m => (Elem c -> e) -> c -> m -> m
mapTo1 Elem c -> e
f m
m = forall a. Semigroup a => a -> a -> a
(<>) m
m forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c e m.
(Generator1 c, Reducer e m) =>
(Elem c -> e) -> c -> m
mapReduce1 Elem c -> e
f
mapFrom1 Elem c -> e
f = forall a. Semigroup a => a -> a -> a
(<>) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c e m.
(Generator1 c, Reducer e m) =>
(Elem c -> e) -> c -> m
mapReduce1 Elem c -> e
f
instance Generator1 (NonEmpty e) where
mapReduce1 :: forall e m.
Reducer e m =>
(Elem (NonEmpty e) -> e) -> NonEmpty e -> m
mapReduce1 Elem (NonEmpty e) -> e
f = forall (t :: * -> *) m a.
(Foldable1 t, Semigroup m) =>
(a -> m) -> t a -> m
foldMap1 (forall c m. Reducer c m => c -> m
unit forall b c a. (b -> c) -> (a -> b) -> a -> c
. Elem (NonEmpty e) -> e
f)
reduce1 :: (Generator1 c, Reducer (Elem c) m) => c -> m
reduce1 :: forall c m. (Generator1 c, Reducer (Elem c) m) => c -> m
reduce1 = forall c e m.
(Generator1 c, Reducer e m) =>
(Elem c -> e) -> c -> m
mapReduce1 forall a. a -> a
id
{-# SPECIALIZE reduce1 :: Reducer a m => NonEmpty a -> m #-}
mapReduceWith1 :: (Generator1 c, Reducer e m) => (m -> n) -> (Elem c -> e) -> c -> n
mapReduceWith1 :: forall c e m n.
(Generator1 c, Reducer e m) =>
(m -> n) -> (Elem c -> e) -> c -> n
mapReduceWith1 m -> n
f Elem c -> e
g = m -> n
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c e m.
(Generator1 c, Reducer e m) =>
(Elem c -> e) -> c -> m
mapReduce1 Elem c -> e
g
{-# INLINE mapReduceWith1 #-}
reduceWith1 :: (Generator1 c, Reducer (Elem c) m) => (m -> n) -> c -> n
reduceWith1 :: forall c m n.
(Generator1 c, Reducer (Elem c) m) =>
(m -> n) -> c -> n
reduceWith1 m -> n
f = m -> n
f forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall c m. (Generator1 c, Reducer (Elem c) m) => c -> m
reduce1
{-# INLINE reduceWith1 #-}