module Flat.Instances.DList
  ()
where

import           Flat.Class
import           Flat.Instances.Mono
import           Data.DList

-- $setup
-- >>> import Flat.Instances.Test
-- >>> import Flat.Instances.Base()
-- >>> import Flat.Run
-- >>> import Data.DList
-- >>> let test = tstBits

{-|
>>> test (Data.DList.fromList [7::Word,7])
(True,19,"10000011 11000001 110")

>>> let l = [7::Word,7] in flat (Data.DList.fromList l) == flat l
True
-}

instance Flat a => Flat (DList a) where
  size :: DList a -> NumBits -> NumBits
size   = [a] -> NumBits -> NumBits
forall mono.
(MonoFoldable mono, Flat (Element mono)) =>
mono -> NumBits -> NumBits
sizeList ([a] -> NumBits -> NumBits)
-> (DList a -> [a]) -> DList a -> NumBits -> NumBits
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList a -> [a]
forall a. DList a -> [a]
toList
  encode :: DList a -> Encoding
encode = [a] -> Encoding
forall mono.
(Flat (Element mono), MonoFoldable mono) =>
mono -> Encoding
encodeList ([a] -> Encoding) -> (DList a -> [a]) -> DList a -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DList a -> [a]
forall a. DList a -> [a]
toList
  decode :: Get (DList a)
decode = [a] -> DList a
forall a. [a] -> DList a
fromList ([a] -> DList a) -> Get [a] -> Get (DList a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Get [a]
forall b. (IsSequence b, Flat (Element b)) => Get b
decodeList