streams-3.2.1: Various Haskell 2010 stream comonads

Copyright(C) 2011 Edward Kmett,
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
Portabilityportable
Safe HaskellSafe
LanguageHaskell98

Data.Stream.Infinite.Functional.Zipper

Contents

Description

This is an infinite bidirectional zipper

Synopsis

The type of streams

tail :: Zipper a -> Zipper a

Move the head of the zipper to the right

untail :: Zipper a -> Zipper a

Move the head of the zipper to the left

intersperse :: a -> Zipper a -> Zipper a

intersperse y xs creates an alternating stream of elements from xs and y.

interleave :: Zipper a -> Zipper a -> Zipper a

Interleave two Zippers xs and ys, alternating elements from each list.

[x1,x2,...] `interleave` [y1,y2,...] == [x1,y1,x2,y2,...]
interleave = (<>)

transpose :: Zipper (Zipper a) -> Zipper (Zipper a)

transpose computes the transposition of a stream of streams.

take :: Integer -> Zipper a -> [a]

drop :: Integer -> Zipper a -> Zipper a

drop n xs drops the first n elements off the front of the sequence xs.

splitAt :: Integer -> Zipper a -> ([a], Zipper a)

splitAt n xs returns a pair consisting of the prefix of xs of length n and the remaining stream immediately following this prefix.

Beware: passing a negative integer as the first argument will cause an error if you access the taken portion

reverse :: [a] -> [a]

reverse xs returns the elements of xs in reverse order. xs must be finite.

(!!) :: Zipper a -> Integer -> a

xs !! n returns the element of the stream xs at index n. Note that the head of the stream has index 0.

unzip :: Zipper (a, b) -> (Zipper a, Zipper b)

The unzip function is the inverse of the zip function.

toSequence :: (Integer -> a) -> Zipper a

head :: Zipper a -> a

Extract the focused element

(<|) :: a -> Zipper a -> Zipper a

Cons before the head of the zipper. The head now points to the new element

uncons :: Zipper a -> (a, Zipper a)

Move the head of the zipper one step to the right, returning the value we move over.

takeWhile :: (a -> Bool) -> Zipper a -> [a]

takeWhile p xs returns the longest prefix of the stream xs for which the predicate p holds.

dropWhile :: (a -> Bool) -> Zipper a -> Zipper a

dropWhile p xs returns the suffix remaining after takeWhile p xs.

Beware: this function may diverge if every element of xs satisfies p, e.g. dropWhile even (repeat 0) will loop.

span :: (a -> Bool) -> Zipper a -> ([a], Zipper a)

span p xs returns the longest prefix of xs that satisfies p, together with the remainder of the stream.

break :: (a -> Bool) -> Zipper a -> ([a], Zipper a)

The break p function is equivalent to span not . p.

isPrefixOf :: Eq a => [a] -> Zipper a -> Bool

The isPrefix function returns True if the first argument is a prefix of the second.

findIndex :: (a -> Bool) -> Zipper a -> Integer

The findIndex function takes a predicate and a stream and returns the index of the first element in the stream that satisfies the predicate,

Beware: findIndex p xs will diverge if none of the elements of xs satisfy p.

elemIndex :: Eq a => a -> Zipper a -> Integer

The elemIndex function returns the index of the first element in the given stream which is equal (by ==) to the query element,

Beware: elemIndex x xs will diverge if none of the elements of xs equal x.

zip :: Zipper a -> Zipper b -> Zipper (a, b)

The zip function takes two streams and returns a list of corresponding pairs.

zip = liftA2 (,)

zipWith :: (a -> b -> c) -> Zipper a -> Zipper b -> Zipper c

The zipWith function generalizes zip. Rather than tupling the functions, the elements are combined using the function passed as the first argument to zipWith.

zipWith = liftA2