module Data.Iteratee.Base.StreamChunk (
StreamChunk (..),
ReadableChunk (..)
)
where
import Prelude hiding (head, tail, dropWhile, length, splitAt )
import qualified Prelude as P
import qualified Data.List as L
import qualified Data.ListLike as LL
import Data.Word
import Foreign.C
import Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal.Array
import System.IO
class LL.ListLike (c el) el => StreamChunk c el where
length :: c el -> Int
length = LL.length
null :: c el -> Bool
null = LL.null
cons :: el -> c el -> c el
cons = LL.cons
head :: c el -> el
head = LL.head
tail :: c el -> c el
tail = LL.tail
findIndex :: (el -> Bool) -> c el -> Maybe Int
findIndex = LL.findIndex
splitAt :: Int -> c el -> (c el, c el)
splitAt = LL.splitAt
dropWhile :: (el -> Bool) -> c el -> c el
dropWhile = LL.dropWhile
fromList :: [el] -> c el
fromList = LL.fromList
toList :: c el -> [el]
toList = LL.toList
cMap :: (StreamChunk c el') => (el -> el') -> c el -> c el'
cMap f = LL.foldr (LL.cons . f) LL.empty
instance StreamChunk [] el where
cMap = map
class (StreamChunk s el, Storable el) => ReadableChunk s el where
readFromPtr :: Ptr (el) -> Int -> IO (s el)
instance ReadableChunk [] Char where
readFromPtr buf l = peekCAStringLen (castPtr buf, l)
instance ReadableChunk [] Word8 where
readFromPtr = flip peekArray
instance ReadableChunk [] Word16 where
readFromPtr = flip peekArray
instance ReadableChunk [] Word32 where
readFromPtr = flip peekArray
instance ReadableChunk [] Word where
readFromPtr = flip peekArray