プログラミングHaskell 7章問題7

type Bit = Int

unfold :: (a -> Bool) -> (a -> b) -> (a -> a) -> a -> [b]
unfold p h t x | p x = []
               | otherwise = h x : unfold p h t (t x)

chop8 :: [Bit] -> [[Bit]]
chop8 = unfold (\x -> null x) (take 8) (drop 8)

map' :: (a -> b) -> [a] -> [b]
map' f = unfold (\x -> null x) (f . head) tail

iterate' :: (a -> a) -> a -> [a]
iterate' f = unfold (\x -> False) (\x -> x) f