Useful-0.0.1: Some useful functions and shorthands.

Useful.IO

Description

IO operations, part of the Useful module.

Synopsis

Documentation

replicateM :: Monad m => Int -> m a -> m [a]Source

repeats an IO function n number of times.

replicateM_ :: Monad m => Int -> m a -> m ()Source

Like replicateM but stores the returns

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

repeats an IO function for every member of a list, using the list item as an arguement

 $ do foreach [1..3] print
 1
 2
 3
 $ do foreach "asjkdnsd" putChar
 asjkdnsd

while :: Monad m => m Bool -> m a -> m ()Source

repeats an IO function until a IO Bool is true

NOTE: Be careful with this function! Better to use recursion. Testing against an item created in the loop will not work.

put :: Show a => a -> IO ()Source

like putStr or putChar but works on any type with "show" defined in a similar way to how print does. Can be thought of as "print" without the trailing linebreak.

NOTE: This means it will print strings with quotes around them. To print strings without quotes use putStr or putStrLn

write :: Show a => a -> IO ()Source

Alias of put

writeln :: Show a => a -> IO ()Source

Alias of print

putln :: Show a => a -> IO ()Source

Alias of print

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

rand :: [a] -> IO aSource

takes a list and returns a random element from that list

 $ rand [1..5]
 5
 $ rand "hello there people"
 'l'