packages feed

lazy-io (empty) → 0.1.0

raw patch · 3 files changed

+69/−0 lines, 3 filesdep +basesetup-changed

Dependencies added: base

Files

+ Setup.lhs view
@@ -0,0 +1,4 @@+#! /usr/bin/env runhaskell++> import Distribution.Simple+> main = defaultMain
+ lazy-io.cabal view
@@ -0,0 +1,31 @@+name:               lazy-io+version:            0.1.0+synopsis:           Lazy IO+description:+    The library provides some basic but useful lazy IO functions.++    Keep in mind that lazy IO is generally discouraged.+    Perhaps a coroutine library (e.g. pipes) will better suit your needs.+license:            BSD3+cabal-version:      >= 1.6+author:             Jakub Waszczuk+maintainer:         waszczuk.kuba@gmail.com+stability:          experimental+category:           System+homepage:           https://github.com/kawu/lazy-io+build-type:         Simple++library+    hs-source-dirs: src++    build-depends:+        base >= 4 && < 5++    exposed-modules:+        Control.Monad.LazyIO++    ghc-options: -Wall++source-repository head+    type: git+    location: https://github.com/kawu/lazy-io.git
+ src/Control/Monad/LazyIO.hs view
@@ -0,0 +1,34 @@+-- | The module is intended to be imported qualified:+--+-- >>> import qualified Control.Monad.LazyIO as LazyIO+++module Control.Monad.LazyIO+( sequence+, mapM+, forM+) where+++import System.IO.Unsafe (unsafeInterleaveIO)+import Prelude hiding (mapM, sequence)+++-- | Lazily evaluate each action in the sequence from left to right,+-- and collect the results.+sequence :: [IO a] -> IO [a]+sequence (mx:mxs) = do+    x   <- mx+    xs  <- unsafeInterleaveIO (sequence mxs)+    return (x : xs)+sequence [] = return []+++-- | `mapM` f is equivalent to `sequence` . `map` f.+mapM :: (a -> IO b) -> [a] -> IO [b]+mapM f = sequence . map f+++-- | `forM` is `mapM` with its arguments flipped.+forM :: [a] -> (a -> IO b) -> IO [b]+forM = flip mapM