module Toml.Codec.Combinator.Monoid
(
all
, any
, sum
, product
, first
, last
) where
import Prelude hiding (all, any, last, product, sum)
import Data.Monoid (All (..), Any (..), First (..), Last (..), Product (..), Sum (..))
import Toml.Codec.Combinator.Primitive (bool)
import Toml.Codec.Di (dimap, dioptional, diwrap)
import Toml.Codec.Types (TomlCodec)
import Toml.Type.Key (Key)
all :: Key -> TomlCodec All
all :: Key -> TomlCodec All
all = (All -> Maybe Bool)
-> (Maybe Bool -> All) -> TomlCodec (Maybe Bool) -> TomlCodec All
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap (Bool -> Maybe Bool
forall a. a -> Maybe a
Just (Bool -> Maybe Bool) -> (All -> Bool) -> All -> Maybe Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. All -> Bool
getAll) (All -> (Bool -> All) -> Maybe Bool -> All
forall b a. b -> (a -> b) -> Maybe a -> b
maybe All
forall a. Monoid a => a
mempty Bool -> All
All) (TomlCodec (Maybe Bool) -> TomlCodec All)
-> (Key -> TomlCodec (Maybe Bool)) -> Key -> TomlCodec All
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlCodec Bool -> TomlCodec (Maybe Bool)
forall a. TomlCodec a -> TomlCodec (Maybe a)
dioptional (TomlCodec Bool -> TomlCodec (Maybe Bool))
-> (Key -> TomlCodec Bool) -> Key -> TomlCodec (Maybe Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TomlCodec Bool
bool
{-# INLINE all #-}
any :: Key -> TomlCodec Any
any :: Key -> TomlCodec Any
any = (Any -> Maybe Bool)
-> (Maybe Bool -> Any) -> TomlCodec (Maybe Bool) -> TomlCodec Any
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap (Bool -> Maybe Bool
forall a. a -> Maybe a
Just (Bool -> Maybe Bool) -> (Any -> Bool) -> Any -> Maybe Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Any -> Bool
getAny) (Any -> (Bool -> Any) -> Maybe Bool -> Any
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Any
forall a. Monoid a => a
mempty Bool -> Any
Any) (TomlCodec (Maybe Bool) -> TomlCodec Any)
-> (Key -> TomlCodec (Maybe Bool)) -> Key -> TomlCodec Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlCodec Bool -> TomlCodec (Maybe Bool)
forall a. TomlCodec a -> TomlCodec (Maybe a)
dioptional (TomlCodec Bool -> TomlCodec (Maybe Bool))
-> (Key -> TomlCodec Bool) -> Key -> TomlCodec (Maybe Bool)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TomlCodec Bool
bool
{-# INLINE any #-}
sum :: (Num a) => (Key -> TomlCodec a) -> Key -> TomlCodec (Sum a)
sum :: forall a. Num a => (Key -> TomlCodec a) -> Key -> TomlCodec (Sum a)
sum Key -> TomlCodec a
codec = (Sum a -> Maybe a)
-> (Maybe a -> Sum a) -> TomlCodec (Maybe a) -> TomlCodec (Sum a)
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> (Sum a -> a) -> Sum a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Sum a -> a
forall a. Sum a -> a
getSum) (Sum a -> (a -> Sum a) -> Maybe a -> Sum a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Sum a
forall a. Monoid a => a
mempty a -> Sum a
forall a. a -> Sum a
Sum) (TomlCodec (Maybe a) -> TomlCodec (Sum a))
-> (Key -> TomlCodec (Maybe a)) -> Key -> TomlCodec (Sum a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlCodec a -> TomlCodec (Maybe a)
forall a. TomlCodec a -> TomlCodec (Maybe a)
dioptional (TomlCodec a -> TomlCodec (Maybe a))
-> (Key -> TomlCodec a) -> Key -> TomlCodec (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TomlCodec a
codec
{-# INLINE sum #-}
product :: (Num a) => (Key -> TomlCodec a) -> Key -> TomlCodec (Product a)
product :: forall a.
Num a =>
(Key -> TomlCodec a) -> Key -> TomlCodec (Product a)
product Key -> TomlCodec a
codec = (Product a -> Maybe a)
-> (Maybe a -> Product a)
-> TomlCodec (Maybe a)
-> TomlCodec (Product a)
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap (a -> Maybe a
forall a. a -> Maybe a
Just (a -> Maybe a) -> (Product a -> a) -> Product a -> Maybe a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Product a -> a
forall a. Product a -> a
getProduct) (Product a -> (a -> Product a) -> Maybe a -> Product a
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Product a
forall a. Monoid a => a
mempty a -> Product a
forall a. a -> Product a
Product) (TomlCodec (Maybe a) -> TomlCodec (Product a))
-> (Key -> TomlCodec (Maybe a)) -> Key -> TomlCodec (Product a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlCodec a -> TomlCodec (Maybe a)
forall a. TomlCodec a -> TomlCodec (Maybe a)
dioptional (TomlCodec a -> TomlCodec (Maybe a))
-> (Key -> TomlCodec a) -> Key -> TomlCodec (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TomlCodec a
codec
{-# INLINE product #-}
first :: (Key -> TomlCodec a) -> Key -> TomlCodec (First a)
first :: forall a. (Key -> TomlCodec a) -> Key -> TomlCodec (First a)
first Key -> TomlCodec a
codec = TomlCodec (Maybe a) -> TomlCodec (First a)
forall b a. Coercible a b => TomlCodec a -> TomlCodec b
diwrap (TomlCodec (Maybe a) -> TomlCodec (First a))
-> (Key -> TomlCodec (Maybe a)) -> Key -> TomlCodec (First a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlCodec a -> TomlCodec (Maybe a)
forall a. TomlCodec a -> TomlCodec (Maybe a)
dioptional (TomlCodec a -> TomlCodec (Maybe a))
-> (Key -> TomlCodec a) -> Key -> TomlCodec (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TomlCodec a
codec
{-# INLINE first #-}
last :: (Key -> TomlCodec a) -> Key -> TomlCodec (Last a)
last :: forall a. (Key -> TomlCodec a) -> Key -> TomlCodec (Last a)
last Key -> TomlCodec a
codec = TomlCodec (Maybe a) -> TomlCodec (Last a)
forall b a. Coercible a b => TomlCodec a -> TomlCodec b
diwrap (TomlCodec (Maybe a) -> TomlCodec (Last a))
-> (Key -> TomlCodec (Maybe a)) -> Key -> TomlCodec (Last a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlCodec a -> TomlCodec (Maybe a)
forall a. TomlCodec a -> TomlCodec (Maybe a)
dioptional (TomlCodec a -> TomlCodec (Maybe a))
-> (Key -> TomlCodec a) -> Key -> TomlCodec (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Key -> TomlCodec a
codec
{-# INLINE last #-}