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 Foreign.Ptr
import Foreign.Storable
import Foreign.Marshal.Array
import System.IO
class StreamChunk c el where
length :: c el -> Int
empty :: c el
null :: c el -> Bool
cons :: el -> c el -> c el
head :: c el -> el
tail :: c el -> c el
findIndex :: (el -> Bool) -> c el -> Maybe Int
splitAt :: Int -> c el -> (c el, c el)
dropWhile :: (el -> Bool) -> c el -> c el
append :: c el -> c el -> c el
fromList :: [el] -> c el
toList :: c el -> [el]
cMap :: (StreamChunk c' el') => (el -> el') -> c el -> c' el'
instance StreamChunk [] el where
length = P.length
empty = []
null [] = True
null _ = False
cons = (:)
head = P.head
tail = P.tail
findIndex = L.findIndex
splitAt = P.splitAt
dropWhile = P.dropWhile
append = (++)
fromList = id
toList = id
cMap = listmap
listmap :: (StreamChunk s' el') => (el -> el') -> [el] -> s' el'
listmap f = foldr (cons . f) empty
class StreamChunk s el => ReadableChunk s el where
readFromPtr :: Ptr (el) -> Int -> IO (s el)
instance (Storable el) => ReadableChunk [] el where
readFromPtr = flip peekArray