>>> for_ [1..4] print 1 2 3 4
echoServer :: Socket -> IO () echoServer socket = forever $ do client <- accept socket forkFinally (echo client) (\_ -> hClose client) where echo :: Handle -> IO () echo client = forever $ hGetLine client >>= hPutStrLn clientNote that "forever" isn't necessarily non-terminating. If the action is in a MonadPlus and short-circuits after some number of iterations. then forever actually returns mzero, effectively short-circuiting its caller.
forkFinally action and_then = mask $ \restore -> forkIO $ try (restore action) >>= and_thenThis function is useful for informing the parent when a child terminates, for example.
>>> bifor (Left []) listToMaybe (find even) Nothing
>>> bifor (Left [1, 2, 3]) listToMaybe (find even) Just (Left 1)
>>> bifor (Right [4, 5]) listToMaybe (find even) Just (Right 4)
>>> bifor ([1, 2, 3], [4, 5]) listToMaybe (find even) Just (1,4)
>>> bifor ([], [4, 5]) listToMaybe (find even) Nothing
>>> bifor_ ("Hello", True) print (print . show)
"Hello"
"True"
>>> bifor_ (Right True) print (print . show) "True"
>>> bifor_ (Left "Hello") print (print . show) "Hello"