packages feed

Stream 0.4.7.1 → 0.4.7.2

raw patch · 2 files changed

+22/−1 lines, 2 files

Files

Data/Stream.hs view
@@ -1,5 +1,13 @@ -- | Streams are infinite lists. Most operations on streams are -- completely analogous to the definition in Data.List.+--+-- The functions provided in this package are fairly+-- careful about totality, termination, and productivity.+-- None of the functions should diverge, provided you adhere to the+-- preconditions mentioned in the documentation.+--+-- Note: I get quite a lot of requests regarding a missing Traversable+-- instance for Streams. This has been left out by design.  module Data.Stream    (@@ -52,6 +60,7 @@    , zip3    , zipWith3    , unzip3+   , distribute    -- * Functions on streams of characters    , words    , unwords@@ -280,6 +289,9 @@  -- | 'span' @p@ @xs@ returns the longest prefix of @xs@ that satisfies -- @p@, together with the remainder of the stream.+--+-- /Beware/: this function may diverge if every element of @xs@+-- satisfies @p@, e.g.  @span even (repeat 0)@ will loop. span :: (a -> Bool) -> Stream a -> ([a], Stream a) span p (Cons x xs)   | p x       = let (trues, falses) = span p xs@@ -287,6 +299,8 @@   | otherwise = ([], Cons x xs)  -- | The 'break' @p@ function is equivalent to 'span' @not . p@.+--+-- /Beware/: this function may diverge for the same reason as @span@. break :: (a -> Bool) -> Stream a -> ([a], Stream a) break p = span (not . p) @@ -406,6 +420,13 @@ zipWith3 :: (a -> b -> c -> d) -> Stream a -> Stream b -> Stream c -> Stream d zipWith3 f ~(Cons x xs) ~(Cons y ys) (Cons z zs) = Cons (f x y z) (zipWith3 f xs ys zs) +-- | The 'distribute' function is similar to the 'sequenceA' function+-- defined in Data.Traversable. Since 'Streams' are not 'Foldable' in+-- general, there is no 'Traversable' instance for streams. They do+-- support a similar notion that only requires the outer type+-- constructor to be functorial.+distribute :: (Functor f) => f (Stream a) -> Stream (f a)+distribute t = Cons (fmap head t) (distribute (fmap tail t))  -- | The 'unzip' function is the inverse of the 'zip' function. unzip :: Stream (a,b) -> (Stream a, Stream b)
Stream.cabal view
@@ -1,5 +1,5 @@ Name:                   Stream-Version:                0.4.7.1+Version:                0.4.7.2 License:                BSD3 License-file:           LICENSE Author:                 Wouter Swierstra <wouter.swierstra@gmail.com>