fs-sim-0.3.0.1: Simulated file systems
Safe HaskellSafe-Inferred
LanguageHaskell2010

System.FS.Sim.Stream

Description

Possibly infinite streams of Maybe as.

Synopsis

Streams

data Stream a Source #

A Stream is a stream of Maybe as, which is possibly infinite or definitely finite.

Finiteness is tracked internally and used for shrinking and the Show instance.

Instances

Instances details
Functor Stream Source # 
Instance details

Defined in System.FS.Sim.Stream

Methods

fmap :: (a -> b) -> Stream a -> Stream b #

(<$) :: a -> Stream b -> Stream a #

Show a => Show (Stream a) Source #

Fully shows a Stream if it is definitely finite, or prints a placeholder string if it is possibly infinite.

Instance details

Defined in System.FS.Sim.Stream

Methods

showsPrec :: Int -> Stream a -> ShowS #

show :: Stream a -> String #

showList :: [Stream a] -> ShowS #

Running

runStream :: Stream a -> (Maybe a, Stream a) Source #

Advance the Stream. Return the Maybe a and the remaining Stream.

Returns Nothing by default if the Stream is empty.

Construction

always :: a -> Stream a Source #

Make a Stream that always generates the given a.

empty :: Stream a Source #

Make an empty Stream.

mkInfinite :: [Maybe a] -> Stream a Source #

Make a Stream that is marked as possibly infinite.

repeating :: [Maybe a] -> Stream a Source #

Make a Stream that infinitely repeats the given list.

unsafeMkFinite :: [Maybe a] -> Stream a Source #

UNSAFE: Make a Stream that is marked as definitely finite.

This is unsafe since a user can pass in any list, and evaluating shrink or show on the resulting Stream will diverge. It is the user's responsibility to only pass in a finite list.

Query

null :: Stream a -> Bool Source #

Return True if the stream is empty.

A stream consisting of only Nothings (even if it is only one) is not considered to be empty.

Generation and shrinking

genFinite Source #

Arguments

:: Int

Requested size of finite stream. Tip: use genMaybe.

-> Gen (Maybe a) 
-> Gen (Stream a) 

Generate a finite Stream of length n.

genInfinite Source #

Arguments

:: Gen (Maybe a)

Tip: use genMaybe.

-> Gen (Stream a) 

Generate an infinite Stream.

genMaybe Source #

Arguments

:: Int

Likelihood of Nothing

-> Int

Likelihood of Just a

-> Gen a 
-> Gen (Maybe a) 

Make a Maybe a generator based on an a generator.

Each element has a chance of being either Nothing or an element generated with the given a generator (wrapped in a Just).

The first argument is the likelihood (as used by frequency) of a Just where Nothing has likelihood 2.

genMaybe' Source #

Arguments

:: Int

Likelihood of Just a

-> Gen a 
-> Gen (Maybe a) 

Like genMaybe, but with the likelihood of Nothing fixed to 2. frequency

shrinkStream :: Stream a -> [Stream a] Source #

Shrink a stream like it is an InfiniteList.

Possibly infinite streams are shrunk differently than lists that are definitely finite, which is to ensure that shrinking terminates. * Possibly infinite streams are shrunk by taking finite prefixes of the argument stream. As such, shrinking a possibly infinite stream creates definitely finite streams. * Definitely finite streams are shrunk like lists are shrunk normally, preserving that the created streams are still definitely finite.