chimera-0.2.0.0: Lazy, infinite streams with O(1) indexing.

Copyright(c) 2018 Andrew Lelechenko
LicenseMIT
MaintainerAndrew Lelechenko <andrew.lelechenko@gmail.com>
Safe HaskellNone
LanguageHaskell2010

Data.Chimera.Unboxed

Contents

Description

Semilazy, infinite stream with O(1) indexing.

Synopsis

Documentation

data Chimera a Source #

Representation of an infinite stream, offering indexing via index in constant time.

This representation is less lazy than Chimera: Querying n-th element triggers computation of first 2 ^ ceiling (logBase 2 n) elements.

index :: Unbox a => Chimera a -> Word -> a Source #

Convert a stream back to a function.

toList :: Unbox a => Chimera a -> [a] Source #

Convert a stream to a list.

Construction

tabulate :: Unbox a => (Word -> a) -> Chimera a Source #

Create a stream from the function.

tabulateFix :: Unbox a => ((Word -> a) -> Word -> a) -> Chimera a Source #

Create a stream from the unfixed function.

tabulateM :: forall m a. (Monad m, Unbox a) => (Word -> m a) -> m (Chimera a) Source #

Create a stream from the monadic function.

tabulateFixM :: forall m a. (Monad m, Unbox a) => ((Word -> m a) -> Word -> m a) -> m (Chimera a) Source #

Create a stream from the unfixed monadic function.

Manipulation

mapWithKey :: (Unbox a, Unbox b) => (Word -> a -> b) -> Chimera a -> Chimera b Source #

Map over all indices and respective elements in the stream.

traverseWithKey :: forall m a b. (Monad m, Unbox a, Unbox b) => (Word -> a -> m b) -> Chimera a -> m (Chimera b) Source #

Traverse over all indices and respective elements in the stream.

zipWithKey :: (Unbox a, Unbox b, Unbox c) => (Word -> a -> b -> c) -> Chimera a -> Chimera b -> Chimera c Source #

Zip two streams with the function, which is provided with an index and respective elements of both streams.

zipWithKeyM :: forall m a b c. (Monad m, Unbox a, Unbox b, Unbox c) => (Word -> a -> b -> m c) -> Chimera a -> Chimera b -> m (Chimera c) Source #

Zip two streams with the monadic function, which is provided with an index and respective elements of both streams.