Copyright  (c) Justin Le 2018 

License  BSD3 
Maintainer  justin@jle.im 
Stability  experimental 
Portability  nonportable 
Safe Haskell  None 
Language  Haskell2010 
Unsafe internaluse functions used in the implementation of
Data.Sequence.NonEmpty. These functions can potentially be used to
break the abstraction of NESeq
and produce unsound sequences, so be
wary!
Synopsis
 data NESeq a = NESeq {}
 pattern (:<) :: a > Seq a > NESeq a
 pattern (:>) :: Seq a > a > NESeq a
 withNonEmpty :: r > (NESeq a > r) > Seq a > r
 toSeq :: NESeq a > Seq a
 singleton :: a > NESeq a
 length :: NESeq a > Int
 fromList :: NonEmpty a > NESeq a
 fromFunction :: Int > (Int > a) > NESeq a
 replicate :: Int > a > NESeq a
 index :: NESeq a > Int > a
 (<) :: a > NESeq a > NESeq a
 (><) :: NESeq a > NESeq a > NESeq a
 (><) :: NESeq a > Seq a > NESeq a
 map :: (a > b) > NESeq a > NESeq b
 foldMapWithIndex :: Semigroup m => (Int > a > m) > NESeq a > m
 traverseWithIndex1 :: Apply f => (Int > a > f b) > NESeq a > f (NESeq b)
 tails :: NESeq a > NESeq (NESeq a)
 zip :: NESeq a > NESeq b > NESeq (a, b)
 zipWith :: (a > b > c) > NESeq a > NESeq b > NESeq c
 unzip :: NESeq (a, b) > (NESeq a, NESeq b)
 sortOnSeq :: Ord b => (a > b) > Seq a > Seq a
 unstableSortOnSeq :: Ord b => (a > b) > Seq a > Seq a
 unzipSeq :: Seq (a, b) > (Seq a, Seq b)
 unzipWithSeq :: (a > (b, c)) > Seq a > (Seq b, Seq c)
Documentation
data NESeq a infixr 5 Source #
A generalpurpose nonempty (by construction) finite sequence type.
Nonemptiness means that:
 Functions that take an
NESeq
can safely operate on it with the assumption that it has at least value.  Functions that return an
NESeq
provide an assurance that the result has at least one value.
Data.Sequence.NonEmpty reexports the API of Data.Sequence,
faithfully reproducing asymptotics, typeclass constraints, and
semantics. Functions that ensure that input and output maps are both
nonempty (like <
) return NESeq
, but
functions that might potentially return an empty map (like
tail
) return a Seq
instead.
You can directly construct an NESeq
with the API from
Data.Sequence.NonEmpty; it's more or less the same as constructing
a normal Seq
, except you don't have access to empty
. There
are also a few ways to construct an NESeq
from a Seq
:
 The
nonEmptySeq
smart constructor will convert a
into aSeq
a
, returningMaybe
(NESeq
a)Nothing
if the originalSeq
was empty.  You can use
:<
,:>
, andinsertSeqAt
to insert a value into aSeq
to create a guaranteedNESeq
.  You can use the
IsNonEmpty
andIsEmpty
patterns to "pattern match" on aSeq
to reveal it as either containing aNESeq
or an empty sequence. withNonEmpty
offers a continuationbased interface for deconstructing aSeq
and treating it as if it were anNESeq
.
You can convert an NESeq
into a Seq
with toSeq
or
IsNonEmpty
, essentially "obscuring" the
nonempty property from the type.
Instances
Monad NESeq Source #  
Functor NESeq Source #  
MonadFix NESeq Source #  
Defined in Data.Sequence.NonEmpty.Internal  
Applicative NESeq Source #  
Foldable NESeq Source # 

Defined in Data.Sequence.NonEmpty.Internal fold :: Monoid m => NESeq m > m # foldMap :: Monoid m => (a > m) > NESeq a > m # foldMap' :: Monoid m => (a > m) > NESeq a > m # foldr :: (a > b > b) > b > NESeq a > b # foldr' :: (a > b > b) > b > NESeq a > b # foldl :: (b > a > b) > b > NESeq a > b # foldl' :: (b > a > b) > b > NESeq a > b # foldr1 :: (a > a > a) > NESeq a > a # foldl1 :: (a > a > a) > NESeq a > a # elem :: Eq a => a > NESeq a > Bool # maximum :: Ord a => NESeq a > a # minimum :: Ord a => NESeq a > a #  
Traversable NESeq Source #  
Eq1 NESeq Source #  
Ord1 NESeq Source #  
Defined in Data.Sequence.NonEmpty.Internal  
Read1 NESeq Source #  
Defined in Data.Sequence.NonEmpty.Internal  
Show1 NESeq Source #  
MonadZip NESeq Source #  mzipWith = zipWith munzip = unzip 
Comonad NESeq Source #  
Traversable1 NESeq Source #  
Foldable1 NESeq Source #  
Alt NESeq Source #  
Apply NESeq Source #  
Bind NESeq Source #  
Extend NESeq Source #  
Eq a => Eq (NESeq a) Source #  
Data a => Data (NESeq a) Source #  
Defined in Data.Sequence.NonEmpty.Internal gfoldl :: (forall d b. Data d => c (d > b) > d > c b) > (forall g. g > c g) > NESeq a > c (NESeq a) # gunfold :: (forall b r. Data b => c (b > r) > c r) > (forall r. r > c r) > Constr > c (NESeq a) # toConstr :: NESeq a > Constr # dataTypeOf :: NESeq a > DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) > Maybe (c (NESeq a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) > Maybe (c (NESeq a)) # gmapT :: (forall b. Data b => b > b) > NESeq a > NESeq a # gmapQl :: (r > r' > r) > r > (forall d. Data d => d > r') > NESeq a > r # gmapQr :: forall r r'. (r' > r > r) > r > (forall d. Data d => d > r') > NESeq a > r # gmapQ :: (forall d. Data d => d > u) > NESeq a > [u] # gmapQi :: Int > (forall d. Data d => d > u) > NESeq a > u # gmapM :: Monad m => (forall d. Data d => d > m d) > NESeq a > m (NESeq a) # gmapMp :: MonadPlus m => (forall d. Data d => d > m d) > NESeq a > m (NESeq a) # gmapMo :: MonadPlus m => (forall d. Data d => d > m d) > NESeq a > m (NESeq a) #  
Ord a => Ord (NESeq a) Source #  
Defined in Data.Sequence.NonEmpty.Internal  
Read a => Read (NESeq a) Source #  
Show a => Show (NESeq a) Source #  
Semigroup (NESeq a) Source #  
ToJSON a => ToJSON (NESeq a) Source #  
Defined in Data.Sequence.NonEmpty.Internal  
FromJSON a => FromJSON (NESeq a) Source #  
NFData a => NFData (NESeq a) Source #  
Defined in Data.Sequence.NonEmpty.Internal 
pattern (:>) :: Seq a > a > NESeq a infixl 5 Source #
O(1). An abstract constructor for an NESeq
that consists of
a "init"
and a "last" Seq
aa
. Similar to :
for NonEmpty
,
but at the end of the list instead of at the beginning.
Can be used to match on the init and last of an NESeq
, and also used
to construct an NESeq
by snocing an item to the end of a Seq
,
ensuring that the result is nonempty.
withNonEmpty :: r > (NESeq a > r) > Seq a > r Source #
O(log n). A general continuationbased way to consume a Seq
as if
it were an NESeq
.
will take a withNonEmpty
def fSeq
. If map is
empty, it will evaluate to def
. Otherwise, a nonempty map NESeq
will be fed to the function f
instead.
nonEmptySeq
==withNonEmpty
Nothing
Just
toSeq :: NESeq a > Seq a Source #
O(1).
Convert a nonempty sequence back into a normal possiblyempty sequence,
for usage with functions that expect Seq
.
Can be thought of as "obscuring" the nonemptiness of the map in its
type. See the IsNotEmpty
pattern.
nonEmptySeq
and
form an isomorphism: they are perfect structurepreserving
inverses of eachother.maybe
empty
toSeq
fromList :: NonEmpty a > NESeq a Source #
\( O(n) \). Create a sequence from a finite list of elements. There
is a function toNonEmpty
in the opposite direction for all instances
of the Foldable1
class, including NESeq
.
fromFunction :: Int > (Int > a) > NESeq a Source #
\( O(n) \). Convert a given sequence length and a function representing that sequence into a sequence.
replicate :: Int > a > NESeq a Source #
\( O(\log n) \). replicate n x
is a sequence consisting of n
copies of x
. Is only defined when n
is positive.
index :: NESeq a > Int > a Source #
\( O(\log(\min(i,ni))) \). The element at the specified position,
counting from 0. The argument should thus be a nonnegative
integer less than the size of the sequence.
If the position is out of range, index
fails with an error.
xs `index` i = toList xs !! i
Caution: index
necessarily delays retrieving the requested
element until the result is forced. It can therefore lead to a space
leak if the result is stored, unforced, in another structure. To retrieve
an element immediately without forcing it, use lookup
or (!?)
.
(<) :: a > NESeq a > NESeq a infixr 5 Source #
\( O(1) \). Add an element to the left end of a nonempty sequence. Mnemonic: a triangle with the single element at the pointy end.
(><) :: NESeq a > NESeq a > NESeq a infixr 5 Source #
\( O(\log(\min(n_1,n_2))) \). Concatenate two nonempty sequences.
map :: (a > b) > NESeq a > NESeq b Source #
Defined here but hidden; intended for use with RULES pragma.
foldMapWithIndex :: Semigroup m => (Int > a > m) > NESeq a > m Source #
O(n). A generalization of foldMap1
, foldMapWithIndex
takes
a folding function that also depends on the element's index, and applies
it to every element in the sequence.
traverseWithIndex1 :: Apply f => (Int > a > f b) > NESeq a > f (NESeq b) Source #
O(n). traverseWithIndex1
is a version of traverse1
that also
offers access to the index of each element.
tails :: NESeq a > NESeq (NESeq a) Source #
\( O(n) \). Returns a sequence of all nonempty suffixes of this sequence, longest first. For example,
tails (fromList (1:[2,3])) = fromList (fromList (1:[2,3]) : [fromList (2:[3]), fromList (3:[])])
Evaluating the \( i \)th suffix takes \( O(\log(\min(i, ni))) \), but evaluating every suffix in the sequence takes \( O(n) \) due to sharing.
zip :: NESeq a > NESeq b > NESeq (a, b) Source #
\( O(\min(n_1,n_2)) \). zip
takes two sequences and returns
a sequence of corresponding pairs. If one input is short, excess
elements are discarded from the right end of the longer sequence.
sortOnSeq :: Ord b => (a > b) > Seq a > Seq a Source #
CPP for new functions not in old containers 
Compatibility layer for sortOn
.
unstableSortOnSeq :: Ord b => (a > b) > Seq a > Seq a Source #
Compatibility layer for unstableSortOn
.