packages feed

io-streams 1.2.0.1 → 1.2.1.1

raw patch · 5 files changed

+80/−3 lines, 5 filesdep ~time

Dependency ranges changed: time

Files

changelog.md view
@@ -1,3 +1,11 @@+# Version 1.2.1.1+  - Dependency bump for time 1.6.++# Version 1.2.1.0+  - Added `System.IO.Streams.mapMaybe` for InputStream.++  - Added `System.IO.Streams.contramapMaybe` for OutputStream.+ # Version 1.2.0.1    - `System.IO.Streams.Attoparsec.parseFromStream`: export more information
io-streams.cabal view
@@ -1,5 +1,5 @@ Name:                io-streams-Version:             1.2.0.1+Version:             1.2.1.1 License:             BSD3 License-file:        LICENSE Category:            Data, Network, IO-Streams@@ -126,7 +126,7 @@                      primitive     >= 0.2   && <0.6,                      process       >= 1     && <1.3,                      text          >= 0.10  && <1.3,-                     time          >= 1.2   && <1.5,+                     time          >= 1.2   && <1.6,                      transformers  >= 0.2   && <0.5,                      vector        >= 0.7   && <0.11,                      zlib-bindings >= 0.1   && <0.2@@ -138,6 +138,7 @@     BangPatterns,     CPP,     DeriveDataTypeable,+    FlexibleContexts,     FlexibleInstances,     GeneralizedNewtypeDeriving,     MultiParamTypeClasses,@@ -211,7 +212,7 @@                      primitive     >= 0.2   && <0.6,                      process       >= 1     && <1.3,                      text          >= 0.10  && <1.3,-                     time          >= 1.2   && <1.5,+                     time          >= 1.2   && <1.6,                      transformers  >= 0.2   && <0.5,                      vector        >= 0.7   && <0.11,                      zlib-bindings >= 0.1   && <0.2,
src/System/IO/Streams/Combinators.hs view
@@ -22,9 +22,11 @@  , map  , mapM  , mapM_+ , mapMaybe  , contramap  , contramapM  , contramapM_+ , contramapMaybe     -- * Filter  , filter@@ -370,6 +372,33 @@   ------------------------------------------------------------------------------+-- | A version of map that discards elements+--+-- @mapMaybe f s@ passes all output from @s@ through the function @f@ and+-- discards elements for which @f s@ evaluates to 'Nothing'.+--+-- Example:+--+-- @+-- ghci> Streams.'System.IO.Streams.fromList' [Just 1, None, Just 3] >>=+--       Streams.'mapMaybe' 'id' >>=+--       Streams.'System.IO.Streams.toList'+-- [1,3]+-- @+--+-- /Since: 1.2.1.0/+mapMaybe :: (a -> Maybe b) -> InputStream a -> IO (InputStream b)+mapMaybe f src = makeInputStream g+  where+    g = do+      s <- read src+      case s of+        Nothing -> return Nothing+        Just x ->+          case f x of+            Nothing -> g+            y -> return y+------------------------------------------------------------------------------ -- | Contravariant counterpart to 'map'. -- -- @contramap f s@ passes all input to @s@ through the function @f@.@@ -415,6 +444,24 @@ contramapM_ f s = makeOutputStream $ \mb -> do     _ <- maybe (return $! ()) (void . f) mb     write mb s+++------------------------------------------------------------------------------+-- | Contravariant counterpart to 'contramapMaybe'.+--+-- @contramap f s@ passes all input to @s@ through the function @f@.+-- Discards all the elements for which @f@ returns 'Nothing'.+--+-- /Since: 1.2.1.0/+--+contramapMaybe :: (a -> Maybe b) -> OutputStream b -> IO (OutputStream a)+contramapMaybe f s = makeOutputStream $ g+    where+      g Nothing = write Nothing s+      g (Just a) =+        case f a of+          Nothing -> return ()+          x -> write x s   ------------------------------------------------------------------------------
src/System/IO/Streams/Internal/Attoparsec.hs view
@@ -3,6 +3,7 @@  {-# LANGUAGE BangPatterns       #-} {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE FlexibleContexts   #-} {-# LANGUAGE OverloadedStrings  #-}  module System.IO.Streams.Internal.Attoparsec
test/System/IO/Streams/Tests/Combinators.hs view
@@ -46,7 +46,9 @@         , testContramap         , testMapM         , testMapM_+        , testMapMaybe         , testContramapM_+        , testContramapMaybe         , testSkipToEof         , testZip         , testZipWith@@ -128,6 +130,15 @@   ------------------------------------------------------------------------------+testMapMaybe :: Test+testMapMaybe = testCase "combinators/mapMaybe" $ do+    is <- fromList [1,2,3::Int] >>= S.mapMaybe (\x -> if odd x then Just (x * x) else Nothing)+    l  <- toList is++    assertEqual "mapMaybe" [1,9] l+++------------------------------------------------------------------------------ testContramapM_ :: Test testContramapM_ = testCase "combinators/contramapM_" $ do     ref <- newIORef 0@@ -135,6 +146,15 @@     _   <- outputToList (contramapM_ (modifyIORef ref . (+)) >=> connect is)      readIORef ref >>= assertEqual "contramapM_" 6+++------------------------------------------------------------------------------+testContramapMaybe :: Test+testContramapMaybe = testCase "combinators/contramapMaybe" $ do+    is  <- fromList [1,2,3::Int]+    l   <- outputToList (contramapMaybe f >=> connect is)+    assertEqual "contramapMaybe" [1,9] l+    where f x = if even x then Nothing else Just $ x * x   ------------------------------------------------------------------------------