| Copyright | (c) Justin Le 2018 | 
|---|---|
| License | BSD3 | 
| Maintainer | justin@jle.im | 
| Stability | experimental | 
| Portability | non-portable | 
| Safe Haskell | None | 
| Language | Haskell2010 | 
Data.Sequence.NonEmpty.Internal
Description
Unsafe internal-use 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 general-purpose non-empty (by construction) finite sequence type.
Non-emptiness means that:
- Functions that take an NESeqcan safely operate on it with the assumption that it has at least value.
- Functions that return an NESeqprovide an assurance that the result has at least one value.
Data.Sequence.NonEmpty re-exports the API of Data.Sequence,
 faithfully reproducing asymptotics, typeclass constraints, and
 semantics.  Functions that ensure that input and output maps are both
 non-empty (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 nonEmptySeqsmart constructor will convert aSeqaMaybe(NESeqa)Nothingif the originalSeqwas empty.
- You can use :<||,:||>, andinsertSeqAtto insert a value into aSeqto create a guaranteedNESeq.
- You can use the IsNonEmptyandIsEmptypatterns to "pattern match" on aSeqto reveal it as either containing aNESeqor an empty sequence.
- withNonEmptyoffers a continuation-based interface for deconstructing a- Seqand treating it as if it were an- NESeq.
You can convert an NESeq into a Seq with toSeq or
 IsNonEmpty, essentially "obscuring" the
 non-empty 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 Methods fold :: Monoid m => NESeq m -> 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 Methods 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 :: (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) # | |
| Read a => Read (NESeq a) Source # | |
| Show a => Show (NESeq a) Source # | |
| Semigroup (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" 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 non-empty.
withNonEmpty :: r -> (NESeq a -> r) -> Seq a -> r Source #
O(log n). A general continuation-based way to consume a Seq as if
 it were an NESeq. withNonEmpty def fSeq.  If map is
 empty, it will evaluate to def.  Otherwise, a non-empty map NESeq
 will be fed to the function f instead.
nonEmptySeq==withNonEmptyNothingJust
toSeq :: NESeq a -> Seq a Source #
O(1).
 Convert a non-empty sequence back into a normal possibly-empty sequence,
 for usage with functions that expect Seq.
Can be thought of as "obscuring" the non-emptiness of the map in its
 type.  See the IsNotEmpty pattern.
nonEmptySeq and 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,n-i))) \). The element at the specified position,
 counting from 0.  The argument should thus be a non-negative
 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 non-empty 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 non-empty 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 non-empty 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, n-i))) \), 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.