-- misc.hs
-- 
-- Miscellaneous Haskell routines.
-- 
-- -- Ed Avis, ed@membled.com, 2000-03-02
-- 

module Misc where
import IO

-- Filter programs without side effects (eg grep, sort, etc)
unix_filter :: (String -> String) -> IO ()
unix_filter f = (hGetContents stdin) >>= mop f >>= putStr

-- mop: turn an ordinary function into a monadic version.  For
-- example, turn a function into an IO computation.
-- 
-- FIXME: isn't this what liftM does?
--
mop :: Monad m => (a -> b) -> (a -> m b)
mop = (return .)

wrap :: ((a' -> a), (b -> b')) -> (a -> b) -> a' -> b'
wrap (before, after) f = after . f . before

