Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Data.List.NonEmpty.Extra
Description
Extra functions for working with NonEmpty
lists. The package
also exports the existing Data.List.NonEmpty functions.
Synopsis
- group :: (Foldable f, Eq a) => f a -> [NonEmpty a]
- cons :: a -> NonEmpty a -> NonEmpty a
- sortOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
- data NonEmpty a = a :| [a]
- (!!) :: HasCallStack => NonEmpty a -> Int -> a
- break :: (a -> Bool) -> NonEmpty a -> ([a], [a])
- cycle :: NonEmpty a -> NonEmpty a
- drop :: Int -> NonEmpty a -> [a]
- dropWhile :: (a -> Bool) -> NonEmpty a -> [a]
- head :: NonEmpty a -> a
- init :: NonEmpty a -> [a]
- iterate :: (a -> a) -> a -> NonEmpty a
- last :: NonEmpty a -> a
- repeat :: a -> NonEmpty a
- reverse :: NonEmpty a -> NonEmpty a
- scanl :: Foldable f => (b -> a -> b) -> b -> f a -> NonEmpty b
- scanl1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
- scanr :: Foldable f => (a -> b -> b) -> b -> f a -> NonEmpty b
- scanr1 :: (a -> a -> a) -> NonEmpty a -> NonEmpty a
- span :: (a -> Bool) -> NonEmpty a -> ([a], [a])
- splitAt :: Int -> NonEmpty a -> ([a], [a])
- tail :: NonEmpty a -> [a]
- take :: Int -> NonEmpty a -> [a]
- takeWhile :: (a -> Bool) -> NonEmpty a -> [a]
- unzip :: Functor f => f (a, b) -> (f a, f b)
- zipWith :: (a -> b -> c) -> NonEmpty a -> NonEmpty b -> NonEmpty c
- length :: NonEmpty a -> Int
- map :: (a -> b) -> NonEmpty a -> NonEmpty b
- zip :: NonEmpty a -> NonEmpty b -> NonEmpty (a, b)
- filter :: (a -> Bool) -> NonEmpty a -> [a]
- xor :: NonEmpty Bool -> Bool
- sort :: Ord a => NonEmpty a -> NonEmpty a
- groupBy :: Foldable f => (a -> a -> Bool) -> f a -> [NonEmpty a]
- nubBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a
- sortBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
- isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool
- toList :: NonEmpty a -> [a]
- inits :: Foldable f => f a -> NonEmpty [a]
- insert :: (Foldable f, Ord a) => a -> f a -> NonEmpty a
- intersperse :: a -> NonEmpty a -> NonEmpty a
- nub :: Eq a => NonEmpty a -> NonEmpty a
- partition :: (a -> Bool) -> NonEmpty a -> ([a], [a])
- permutations :: [a] -> NonEmpty [a]
- singleton :: a -> NonEmpty a
- tails :: Foldable f => f a -> NonEmpty [a]
- transpose :: NonEmpty (NonEmpty a) -> NonEmpty (NonEmpty a)
- unfoldr :: (a -> (b, Maybe a)) -> a -> NonEmpty b
- uncons :: NonEmpty a -> (a, Maybe (NonEmpty a))
- (<|) :: a -> NonEmpty a -> NonEmpty a
- unfold :: (a -> (b, Maybe a)) -> a -> NonEmpty b
- append :: NonEmpty a -> NonEmpty a -> NonEmpty a
- appendList :: NonEmpty a -> [a] -> NonEmpty a
- fromList :: HasCallStack => [a] -> NonEmpty a
- group1 :: Eq a => NonEmpty a -> NonEmpty (NonEmpty a)
- groupAllWith :: Ord b => (a -> b) -> [a] -> [NonEmpty a]
- groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
- groupBy1 :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty (NonEmpty a)
- groupWith :: (Foldable f, Eq b) => (a -> b) -> f a -> [NonEmpty a]
- groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a)
- inits1 :: NonEmpty a -> NonEmpty (NonEmpty a)
- nonEmpty :: [a] -> Maybe (NonEmpty a)
- permutations1 :: NonEmpty a -> NonEmpty (NonEmpty a)
- prependList :: [a] -> NonEmpty a -> NonEmpty a
- some1 :: Alternative f => f a -> f (NonEmpty a)
- sortWith :: Ord o => (a -> o) -> NonEmpty a -> NonEmpty a
- tails1 :: NonEmpty a -> NonEmpty (NonEmpty a)
- (|:) :: [a] -> a -> NonEmpty a
- (|>) :: NonEmpty a -> a -> NonEmpty a
- snoc :: NonEmpty a -> a -> NonEmpty a
- (!?) :: NonEmpty a -> Int -> Maybe a
- appendl :: NonEmpty a -> [a] -> NonEmpty a
- appendr :: [a] -> NonEmpty a -> NonEmpty a
- sortOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
- union :: Eq a => NonEmpty a -> NonEmpty a -> NonEmpty a
- unionBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a -> NonEmpty a
- nubOrd :: Ord a => NonEmpty a -> NonEmpty a
- nubOrdBy :: (a -> a -> Ordering) -> NonEmpty a -> NonEmpty a
- nubOrdOn :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty a
- maximum1 :: Ord a => NonEmpty a -> a
- minimum1 :: Ord a => NonEmpty a -> a
- maximumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a
- minimumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a
- maximumOn1 :: Ord b => (a -> b) -> NonEmpty a -> a
- minimumOn1 :: Ord b => (a -> b) -> NonEmpty a -> a
- foldl1' :: (a -> a -> a) -> NonEmpty a -> a
- repeatedly :: (NonEmpty a -> (b, [a])) -> NonEmpty a -> NonEmpty b
- compareLength :: NonEmpty a -> Int -> Ordering
Documentation
Constructors
a :| [a] |
Instances
MonadZip NonEmpty | |||||
Foldable1 NonEmpty | |||||
Defined in Data.Foldable1 Methods fold1 :: Semigroup m => NonEmpty m -> m foldMap1 :: Semigroup m => (a -> m) -> NonEmpty a -> m foldMap1' :: Semigroup m => (a -> m) -> NonEmpty a -> m toNonEmpty :: NonEmpty a -> NonEmpty a maximum :: Ord a => NonEmpty a -> a minimum :: Ord a => NonEmpty a -> a foldrMap1 :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b foldlMap1' :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b foldlMap1 :: (a -> b) -> (b -> a -> b) -> NonEmpty a -> b foldrMap1' :: (a -> b) -> (a -> b -> b) -> NonEmpty a -> b | |||||
Eq1 NonEmpty | |||||
Defined in Data.Functor.Classes | |||||
Ord1 NonEmpty | |||||
Defined in Data.Functor.Classes Methods liftCompare :: (a -> b -> Ordering) -> NonEmpty a -> NonEmpty b -> Ordering | |||||
Read1 NonEmpty | |||||
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS (NonEmpty a) liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [NonEmpty a] liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec (NonEmpty a) liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [NonEmpty a] | |||||
Show1 NonEmpty | |||||
Defined in Data.Functor.Classes Methods liftShowsPrec :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> Int -> NonEmpty a -> ShowS liftShowList :: (Int -> a -> ShowS) -> ([a] -> ShowS) -> [NonEmpty a] -> ShowS | |||||
NFData1 NonEmpty | |||||
Defined in Control.DeepSeq | |||||
Applicative NonEmpty | |||||
Functor NonEmpty | |||||
Monad NonEmpty | |||||
Foldable NonEmpty | |||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => NonEmpty m -> m # foldMap :: Monoid m => (a -> m) -> NonEmpty a -> m # foldMap' :: Monoid m => (a -> m) -> NonEmpty a -> m # foldr :: (a -> b -> b) -> b -> NonEmpty a -> b # foldr' :: (a -> b -> b) -> b -> NonEmpty a -> b # foldl :: (b -> a -> b) -> b -> NonEmpty a -> b # foldl' :: (b -> a -> b) -> b -> NonEmpty a -> b # foldr1 :: (a -> a -> a) -> NonEmpty a -> a # foldl1 :: (a -> a -> a) -> NonEmpty a -> a # elem :: Eq a => a -> NonEmpty a -> Bool # maximum :: Ord a => NonEmpty a -> a # minimum :: Ord a => NonEmpty a -> a # | |||||
Traversable NonEmpty | |||||
Defined in GHC.Internal.Data.Traversable | |||||
Generic1 NonEmpty | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
Lift a => Lift (NonEmpty a :: Type) | |||||
NFData a => NFData (NonEmpty a) | |||||
Defined in Control.DeepSeq | |||||
Semigroup (NonEmpty a) | |||||
Generic (NonEmpty a) | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
IsList (NonEmpty a) | |||||
Read a => Read (NonEmpty a) | |||||
Show a => Show (NonEmpty a) | |||||
Eq a => Eq (NonEmpty a) | |||||
Ord a => Ord (NonEmpty a) | |||||
type Rep1 NonEmpty | |||||
Defined in GHC.Internal.Generics type Rep1 NonEmpty = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) Par1 :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec1 []))) | |||||
type Rep (NonEmpty a) | |||||
Defined in GHC.Internal.Generics type Rep (NonEmpty a) = D1 ('MetaData "NonEmpty" "GHC.Internal.Base" "ghc-internal" 'False) (C1 ('MetaCons ":|" ('InfixI 'RightAssociative 5) 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 a) :*: S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [a]))) | |||||
type Item (NonEmpty a) | |||||
Defined in GHC.Internal.IsList type Item (NonEmpty a) = a |
isPrefixOf :: Eq a => [a] -> NonEmpty a -> Bool #
intersperse :: a -> NonEmpty a -> NonEmpty a #
permutations :: [a] -> NonEmpty [a] #
appendList :: NonEmpty a -> [a] -> NonEmpty a #
groupAllWith :: Ord b => (a -> b) -> [a] -> [NonEmpty a] #
groupAllWith1 :: Ord b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) #
groupWith1 :: Eq b => (a -> b) -> NonEmpty a -> NonEmpty (NonEmpty a) #
permutations1 :: NonEmpty a -> NonEmpty (NonEmpty a) #
prependList :: [a] -> NonEmpty a -> NonEmpty a #
(|:) :: [a] -> a -> NonEmpty a infixl 5 Source #
O(n). Append an element to a list.
[1,2,3] |: 4 |> 5 == 1 :| [2,3,4,5]
(|>) :: NonEmpty a -> a -> NonEmpty a infixl 5 Source #
O(n). Append an element to a non-empty list.
(1 :| [2,3]) |> 4 |> 5 == 1 :| [2,3,4,5]
(!?) :: NonEmpty a -> Int -> Maybe a infixl 9 Source #
A total variant of the list index function (!?)
.
(2 :| [3,4]) !? 1 == Just 3 (2 :| [3,4]) !? (-1) == Nothing (1 :| []) !? 1 == Nothing
appendl :: NonEmpty a -> [a] -> NonEmpty a Source #
Append a list to a non-empty list.
appendl (1 :| [2,3]) [4,5] == 1 :| [2,3,4,5]
appendr :: [a] -> NonEmpty a -> NonEmpty a Source #
Append a non-empty list to a list.
appendr [1,2,3] (4 :| [5]) == 1 :| [2,3,4,5]
union :: Eq a => NonEmpty a -> NonEmpty a -> NonEmpty a Source #
Return the union of two non-empty lists. Duplicates, and elements of the first list, are removed from the the second list, but if the first list contains duplicates, so will the result.
(1 :| [3, 5, 3]) `union` (4 :| [5, 3, 5, 2]) == 1 :| [3, 5, 3, 4, 2]
unionBy :: (a -> a -> Bool) -> NonEmpty a -> NonEmpty a -> NonEmpty a Source #
The non-overloaded version of union
.
maximumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a Source #
The largest element of a non-empty list with respect to the given comparison function.
minimumBy1 :: (a -> a -> Ordering) -> NonEmpty a -> a Source #
The least element of a non-empty list with respect to the given comparison function.
maximumOn1 :: Ord b => (a -> b) -> NonEmpty a -> a Source #
A version of maximum1
where the comparison is done on some extracted value.
minimumOn1 :: Ord b => (a -> b) -> NonEmpty a -> a Source #
A version of minimum1
where the comparison is done on some extracted value.
repeatedly :: (NonEmpty a -> (b, [a])) -> NonEmpty a -> NonEmpty b Source #
Apply some operation repeatedly, producing an element of output and the remainder of the list.
compareLength :: NonEmpty a -> Int -> Ordering Source #
Use compareLength
xs
n
as a safer and faster alternative
to compare
(length
xs
) n
. Similarly, it's better
to write compareLength xs 10 == LT
instead of length xs < 10
.
While length
would force and traverse
the entire spine of xs
(which could even diverge if xs
is infinite),
compareLength
traverses at most n
elements to determine its result.
>>>
compareLength ('a' :| []) 1
EQ>>>
compareLength ('a' :| ['b']) 3
LT>>>
compareLength (0 :| [1..]) 100
GT>>>
compareLength undefined 0
GT>>>
compareLength ('a' :| 'b' : undefined) 1
GT
Since: 4.21.0.0