mapM_ for bytestring

Erik de Castro Lopo mle+hs at mega-nerd.com
Sun Sep 1 13:18:32 CEST 2013


Artyom Kazak wrote:

> Would this be an appropriate place to propose adding mapM_ (and then  
> possibly mapM) to bytestring library?

Err, mapM is defined as:

    mapM :: Monad m => (a -> m b) -> [a] -> m [b]


in that the second parameter is a list. ByteStrings are not lists,
they're chunks of bytes. Besides, you can just do:

  
    let bs = "This is a bytestring"
    mapM someFUnctions $ BS.unpack bs

or define a function:

    mapBSM :: Monad m => (Char -> m a) -> ByteString -> m [a]
    mapBSM f bs = mapM f $ BS.unpack bs

and similar for mapBSM_.

Erik
-- 
----------------------------------------------------------------------
Erik de Castro Lopo
http://www.mega-nerd.com/




More information about the Libraries mailing list