module Data.Tensort.Utils.Convert (rawBitsToBytes) where
import Data.Tensort.Utils.Split (splitEvery)
import Data.Tensort.Utils.Types (Byte, Sortable (..), TensortProps (..), fromSortBit, Bit)
rawBitsToBytes :: [Bit] -> TensortProps -> [Byte]
rawBitsToBytes :: [Bit] -> TensortProps -> [[Bit]]
rawBitsToBytes [Bit]
bits TensortProps
tsProps = ([Bit] -> [[Bit]] -> [[Bit]]) -> [[Bit]] -> [[Bit]] -> [[Bit]]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr [Bit] -> [[Bit]] -> [[Bit]]
acc [] (Bit -> [Bit] -> [[Bit]]
forall a. Bit -> [a] -> [[a]]
splitEvery (TensortProps -> Bit
bytesize TensortProps
tsProps) [Bit]
bits)
where
acc :: [Bit] -> [Byte] -> [Byte]
acc :: [Bit] -> [[Bit]] -> [[Bit]]
acc [Bit]
byte [[Bit]]
bytes = [[Bit]]
bytes [[Bit]] -> [[Bit]] -> [[Bit]]
forall a. [a] -> [a] -> [a]
++ [Sortable -> [Bit]
fromSortBit (TensortProps -> SortAlg
subAlgorithm TensortProps
tsProps ([Bit] -> Sortable
SortBit [Bit]
byte))]