module Toml.Codec.Combinator.Set
(
arraySetOf
, arrayIntSet
, arrayHashSetOf
, set
, intSet
, hashSet
) where
import Data.Hashable (Hashable)
import Data.HashSet (HashSet)
import Data.IntSet (IntSet)
import Data.Set (Set)
import Toml.Codec.BiMap (TomlBiMap)
import Toml.Codec.BiMap.Conversion (_HashSet, _IntSet, _Set)
import Toml.Codec.Combinator.Common (match)
import Toml.Codec.Combinator.List (list)
import Toml.Codec.Di (dimap)
import Toml.Codec.Types (TomlCodec)
import Toml.Type.AnyValue (AnyValue (..))
import Toml.Type.Key (Key)
import qualified Data.HashSet as HS
import qualified Data.IntSet as IS
import qualified Data.Set as S
arraySetOf :: Ord a => TomlBiMap a AnyValue -> Key -> TomlCodec (Set a)
arraySetOf :: TomlBiMap a AnyValue -> Key -> TomlCodec (Set a)
arraySetOf = TomlBiMap (Set a) AnyValue -> Key -> TomlCodec (Set a)
forall a. TomlBiMap a AnyValue -> Key -> TomlCodec a
match (TomlBiMap (Set a) AnyValue -> Key -> TomlCodec (Set a))
-> (TomlBiMap a AnyValue -> TomlBiMap (Set a) AnyValue)
-> TomlBiMap a AnyValue
-> Key
-> TomlCodec (Set a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlBiMap a AnyValue -> TomlBiMap (Set a) AnyValue
forall a.
Ord a =>
TomlBiMap a AnyValue -> TomlBiMap (Set a) AnyValue
_Set
{-# INLINE arraySetOf #-}
arrayIntSet :: Key -> TomlCodec IntSet
arrayIntSet :: Key -> TomlCodec IntSet
arrayIntSet = TomlBiMap IntSet AnyValue -> Key -> TomlCodec IntSet
forall a. TomlBiMap a AnyValue -> Key -> TomlCodec a
match TomlBiMap IntSet AnyValue
_IntSet
{-# INLINE arrayIntSet #-}
arrayHashSetOf
:: (Hashable a, Eq a)
=> TomlBiMap a AnyValue
-> Key
-> TomlCodec (HashSet a)
arrayHashSetOf :: TomlBiMap a AnyValue -> Key -> TomlCodec (HashSet a)
arrayHashSetOf = TomlBiMap (HashSet a) AnyValue -> Key -> TomlCodec (HashSet a)
forall a. TomlBiMap a AnyValue -> Key -> TomlCodec a
match (TomlBiMap (HashSet a) AnyValue -> Key -> TomlCodec (HashSet a))
-> (TomlBiMap a AnyValue -> TomlBiMap (HashSet a) AnyValue)
-> TomlBiMap a AnyValue
-> Key
-> TomlCodec (HashSet a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TomlBiMap a AnyValue -> TomlBiMap (HashSet a) AnyValue
forall a.
(Eq a, Hashable a) =>
TomlBiMap a AnyValue -> TomlBiMap (HashSet a) AnyValue
_HashSet
{-# INLINE arrayHashSetOf #-}
set :: forall a . Ord a => TomlCodec a -> Key -> TomlCodec (Set a)
set :: TomlCodec a -> Key -> TomlCodec (Set a)
set codec :: TomlCodec a
codec key :: Key
key = (Set a -> [a])
-> ([a] -> Set a) -> TomlCodec [a] -> TomlCodec (Set a)
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap Set a -> [a]
forall a. Set a -> [a]
S.toList [a] -> Set a
forall a. Ord a => [a] -> Set a
S.fromList (TomlCodec a -> Key -> TomlCodec [a]
forall a. TomlCodec a -> Key -> TomlCodec [a]
list TomlCodec a
codec Key
key)
{-# INLINE set #-}
intSet :: TomlCodec Int -> Key -> TomlCodec IntSet
intSet :: TomlCodec Int -> Key -> TomlCodec IntSet
intSet codec :: TomlCodec Int
codec key :: Key
key = (IntSet -> [Int])
-> ([Int] -> IntSet) -> TomlCodec [Int] -> TomlCodec IntSet
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap IntSet -> [Int]
IS.toList [Int] -> IntSet
IS.fromList (TomlCodec Int -> Key -> TomlCodec [Int]
forall a. TomlCodec a -> Key -> TomlCodec [a]
list TomlCodec Int
codec Key
key)
{-# INLINE intSet #-}
hashSet :: forall a . (Hashable a, Eq a) => TomlCodec a -> Key -> TomlCodec (HashSet a)
hashSet :: TomlCodec a -> Key -> TomlCodec (HashSet a)
hashSet codec :: TomlCodec a
codec key :: Key
key = (HashSet a -> [a])
-> ([a] -> HashSet a) -> TomlCodec [a] -> TomlCodec (HashSet a)
forall b a. (b -> a) -> (a -> b) -> TomlCodec a -> TomlCodec b
dimap HashSet a -> [a]
forall a. HashSet a -> [a]
HS.toList [a] -> HashSet a
forall a. (Eq a, Hashable a) => [a] -> HashSet a
HS.fromList (TomlCodec a -> Key -> TomlCodec [a]
forall a. TomlCodec a -> Key -> TomlCodec [a]
list TomlCodec a
codec Key
key)
{-# INLINE hashSet #-}