module Rattletrap.Encode.List ( putList ) where import Rattletrap.Encode.Word32le import Rattletrap.Type.List import Rattletrap.Type.Word32le import qualified Data.Binary as Binary putList :: (a -> Binary.Put) -> List a -> Binary.Put putList :: (a -> Put) -> List a -> Put putList a -> Put putElement List a list = do let elements :: [a] elements = List a -> [a] forall a. List a -> [a] listValue List a list Word32le -> Put putWord32 (Word32 -> Word32le Word32le (Int -> Word32 forall a b. (Integral a, Num b) => a -> b fromIntegral ([a] -> Int forall (t :: * -> *) a. Foldable t => t a -> Int length [a] elements))) (a -> Put) -> [a] -> Put forall (t :: * -> *) (m :: * -> *) a b. (Foldable t, Monad m) => (a -> m b) -> t a -> m () mapM_ a -> Put putElement [a] elements