strict-containers-0.1.0.0: Various strict container types
Safe Haskell None
Language Haskell2010

Data.Sequence.Strict

Description

Strict variants of Seq operations.

Synopsis

Documentation

data StrictSeq a where Source #

A newtype wrapper around a Seq , representing a general-purpose finite sequence that is strict in its values.

This strictness is not enforced at the type level, but rather by the construction functions in this module. These functions essentially just wrap the original Data.Sequence functions while forcing the provided value to WHNF.

Bundled Patterns

pattern Empty :: StrictSeq a

A bidirectional pattern synonym matching an empty sequence.

pattern (:<|) :: a -> StrictSeq a -> StrictSeq a infixr 5

A bidirectional pattern synonym viewing the front of a non-empty sequence.

pattern (:|>) :: StrictSeq a -> a -> StrictSeq a infixl 5

A bidirectional pattern synonym viewing the rear of a non-empty sequence.

Instances

Instances details
Functor StrictSeq Source #
Instance details

Defined in Data.Sequence.Strict

Foldable StrictSeq Source #
Instance details

Defined in Data.Sequence.Strict

Traversable StrictSeq Source #
Instance details

Defined in Data.Sequence.Strict

Eq a => Eq ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

Ord a => Ord ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

Show a => Show ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

Semigroup ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

Monoid ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

ToJSON a => ToJSON ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

FromJSON a => FromJSON ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

NFData a => NFData ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

NoThunks a => NoThunks ( StrictSeq a) Source #

Instance for StrictSeq checks elements only

The internal fingertree in Seq might have thunks, which is essential for its asymptotic complexity.

Instance details

Defined in Data.Sequence.Strict

Serialise a => Serialise ( StrictSeq a) Source #
Instance details

Defined in Data.Sequence.Strict

forceToStrict :: Seq a -> StrictSeq a Source #

Convert a Seq into a StrictSeq by forcing each element to WHNF.

Construction

empty :: StrictSeq a Source #

\( O(1) \) . The empty sequence.

singleton :: a -> StrictSeq a Source #

\( O(1) \) . A singleton sequence.

(<|) :: a -> StrictSeq a -> StrictSeq a infixr 5 Source #

\( O(1) \) . Add an element to the left end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

(|>) :: StrictSeq a -> a -> StrictSeq a infixl 5 Source #

\( O(1) \) . Add an element to the right end of a sequence. Mnemonic: a triangle with the single element at the pointy end.

(><) :: StrictSeq a -> StrictSeq a -> StrictSeq a infixr 5 Source #

\( O(\log(\min(n_1,n_2))) \) . Concatenate two sequences.

Deconstruction

Additional functions for deconstructing sequences are available via the Foldable instance of Seq .

Queries

null :: StrictSeq a -> Bool Source #

\( O(1) \) . Is this the empty sequence?

length :: StrictSeq a -> Int Source #

\( O(1) \) . The number of elements in the sequence.

Scans

scanl :: (a -> b -> a) -> a -> StrictSeq b -> StrictSeq a Source #

scanl is similar to foldl , but returns a sequence of reduced values from the left:

scanl f z (fromList [x1, x2, ...]) = fromList [z, z `f` x1, (z `f` x1) `f` x2, ...]

Sublists

Sequential searches

dropWhileL :: (a -> Bool ) -> StrictSeq a -> StrictSeq a Source #

\( O(i) \) where \( i \) is the prefix length. dropWhileL p xs returns the suffix remaining after takeWhileL p xs .

dropWhileR :: (a -> Bool ) -> StrictSeq a -> StrictSeq a Source #

\( O(i) \) where \( i \) is the suffix length. dropWhileR p xs returns the prefix remaining after takeWhileR p xs .

dropWhileR p xs is equivalent to reverse ( dropWhileL p ( reverse xs)) .

spanl :: (a -> Bool ) -> StrictSeq a -> ( StrictSeq a, StrictSeq a) Source #

\( O(i) \) where \( i \) is the prefix length. spanl , applied to a predicate p and a sequence xs , returns a pair whose first element is the longest prefix (possibly empty) of xs of elements that satisfy p and the second element is the remainder of the sequence.

spanr :: (a -> Bool ) -> StrictSeq a -> ( StrictSeq a, StrictSeq a) Source #

\( O(i) \) where \( i \) is the suffix length. spanr , applied to a predicate p and a sequence xs , returns a pair whose first element is the longest suffix (possibly empty) of xs of elements that satisfy p and the second element is the remainder of the sequence.

Indexing

lookup :: Int -> StrictSeq a -> Maybe a Source #

\( O(\log(\min(i,n-i))) \) . The element at the specified position, counting from 0. If the specified position is negative or at least the length of the sequence, lookup returns Nothing .

0 <= i < length xs ==> lookup i xs == Just (toList xs !! i)
i < 0 || i >= length xs ==> lookup i xs = Nothing

Unlike index , this can be used to retrieve an element without forcing it. For example, to insert the fifth element of a sequence xs into a Map m at key k , you could use

case lookup 5 xs of
  Nothing -> m
  Just x -> insert k x m

(!?) :: StrictSeq a -> Int -> Maybe a Source #

\( O(\log(\min(i,n-i))) \) . A flipped, infix version of lookup .

take :: Int -> StrictSeq a -> StrictSeq a Source #

\( O(\log(\min(i,n-i))) \) . The first i elements of a sequence. If i is negative, take i s yields the empty sequence. If the sequence contains fewer than i elements, the whole sequence is returned.

takeLast :: Int -> StrictSeq a -> StrictSeq a Source #

Take the last n elements

Returns the entire sequence if it has fewer than n elements.

Inherits asymptotic complexity from drop .

drop :: Int -> StrictSeq a -> StrictSeq a Source #

\( O(\log(\min(i,n-i))) \) . Elements of a sequence after the first i . If i is negative, drop i s yields the whole sequence. If the sequence contains fewer than i elements, the empty sequence is returned.

dropLast :: Int -> StrictSeq a -> StrictSeq a Source #

Drop the last n elements

Returns the Empty sequence if it has fewer than n elements.

Inherits asymptotic complexity from take .

splitAt :: Int -> StrictSeq a -> ( StrictSeq a, StrictSeq a) Source #

\( O(\log(\min(i,n-i))) \) . Split a sequence at a given position. splitAt i s = ( take i s, drop i s) .

splitAtEnd :: Int -> StrictSeq a -> ( StrictSeq a, StrictSeq a) Source #

Split at the given position counting from the end of the sequence.

Inherits asymptotic complexity from splitAt .

Indexing with predicates

findIndexL :: (a -> Bool ) -> StrictSeq a -> Maybe Int Source #

findIndexL p xs finds the index of the leftmost element that satisfies p , if any exist.

findIndicesL :: (a -> Bool ) -> StrictSeq a -> [ Int ] Source #

findIndicesL p finds all indices of elements that satisfy p , in ascending order.

findIndexR :: (a -> Bool ) -> StrictSeq a -> Maybe Int Source #

findIndexR p xs finds the index of the rightmost element that satisfies p , if any exist.

findIndicesR :: (a -> Bool ) -> StrictSeq a -> [ Int ] Source #

findIndicesR p finds all indices of elements that satisfy p , in descending order.

Zips and unzips