Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
Data.List.Compat
Synopsis
- group :: Eq a => [a] -> [[a]]
- unzip :: [(a, b)] -> ([a], [b])
- data List a
- foldr :: Foldable t => (a -> b -> b) -> b -> t a -> b
- null :: Foldable t => t a -> Bool
- length :: Foldable t => t a -> Int
- elem :: (Foldable t, Eq a) => a -> t a -> Bool
- foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
- foldl' :: Foldable t => (b -> a -> b) -> b -> t a -> b
- foldl1 :: Foldable t => (a -> a -> a) -> t a -> a
- foldr1 :: Foldable t => (a -> a -> a) -> t a -> a
- maximum :: (Foldable t, Ord a) => t a -> a
- minimum :: (Foldable t, Ord a) => t a -> a
- product :: (Foldable t, Num a) => t a -> a
- sum :: (Foldable t, Num a) => t a -> a
- map :: (a -> b) -> [a] -> [b]
- intersperse :: a -> [a] -> [a]
- scanl :: (b -> a -> b) -> b -> [a] -> [b]
- scanr :: (a -> b -> b) -> b -> [a] -> [b]
- scanl1 :: (a -> a -> a) -> [a] -> [a]
- scanr1 :: (a -> a -> a) -> [a] -> [a]
- transpose :: [[a]] -> [[a]]
- sortBy :: (a -> a -> Ordering) -> [a] -> [a]
- head :: HasCallStack => [a] -> a
- tail :: HasCallStack => [a] -> [a]
- last :: HasCallStack => [a] -> a
- init :: HasCallStack => [a] -> [a]
- singleton :: a -> [a]
- uncons :: [a] -> Maybe (a, [a])
- unfoldr :: (b -> Maybe (a, b)) -> b -> [a]
- sort :: Ord a => [a] -> [a]
- sortOn :: Ord b => (a -> b) -> [a] -> [a]
- reverse :: [a] -> [a]
- inits :: [a] -> [[a]]
- tails :: [a] -> [[a]]
- iterate :: (a -> a) -> a -> [a]
- repeat :: a -> [a]
- cycle :: HasCallStack => [a] -> [a]
- insert :: Ord a => a -> [a] -> [a]
- take :: Int -> [a] -> [a]
- drop :: Int -> [a] -> [a]
- splitAt :: Int -> [a] -> ([a], [a])
- takeWhile :: (a -> Bool) -> [a] -> [a]
- dropWhile :: (a -> Bool) -> [a] -> [a]
- span :: (a -> Bool) -> [a] -> ([a], [a])
- break :: (a -> Bool) -> [a] -> ([a], [a])
- filter :: (a -> Bool) -> [a] -> [a]
- partition :: (a -> Bool) -> [a] -> ([a], [a])
- groupBy :: (a -> a -> Bool) -> [a] -> [[a]]
- permutations :: [a] -> [[a]]
- isPrefixOf :: Eq a => [a] -> [a] -> Bool
- nub :: Eq a => [a] -> [a]
- nubBy :: (a -> a -> Bool) -> [a] -> [a]
- (!!) :: HasCallStack => [a] -> Int -> a
- zip :: [a] -> [b] -> [(a, b)]
- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
- lines :: String -> [String]
- words :: String -> [String]
- unlines :: [String] -> String
- unwords :: [String] -> String
- (++) :: [a] -> [a] -> [a]
- all :: Foldable t => (a -> Bool) -> t a -> Bool
- replicate :: Int -> a -> [a]
- concat :: Foldable t => t [a] -> [a]
- and :: Foldable t => t Bool -> Bool
- any :: Foldable t => (a -> Bool) -> t a -> Bool
- concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
- notElem :: (Foldable t, Eq a) => a -> t a -> Bool
- or :: Foldable t => t Bool -> Bool
- lookup :: Eq a => a -> [(a, b)] -> Maybe b
- unzip3 :: [(a, b, c)] -> ([a], [b], [c])
- zip3 :: [a] -> [b] -> [c] -> [(a, b, c)]
- zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
- intercalate :: [a] -> [[a]] -> [a]
- find :: Foldable t => (a -> Bool) -> t a -> Maybe a
- maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- minimumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
- mapAccumL :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
- mapAccumR :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b)
- foldl1' :: HasCallStack => (a -> a -> a) -> [a] -> a
- (!?) :: [a] -> Int -> Maybe a
- iterate' :: (a -> a) -> a -> [a]
- scanl' :: (b -> a -> b) -> b -> [a] -> [b]
- unsnoc :: [a] -> Maybe ([a], a)
- (\\) :: Eq a => [a] -> [a] -> [a]
- genericLength :: Num i => [a] -> i
- zipWith4 :: (a -> b -> c -> d -> e) -> [a] -> [b] -> [c] -> [d] -> [e]
- zipWith5 :: (a -> b -> c -> d -> e -> f) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f]
- zipWith6 :: (a -> b -> c -> d -> e -> f -> g) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g]
- zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h]
- delete :: Eq a => a -> [a] -> [a]
- deleteBy :: (a -> a -> Bool) -> a -> [a] -> [a]
- deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- dropWhileEnd :: (a -> Bool) -> [a] -> [a]
- elemIndex :: Eq a => a -> [a] -> Maybe Int
- elemIndices :: Eq a => a -> [a] -> [Int]
- findIndex :: (a -> Bool) -> [a] -> Maybe Int
- findIndices :: (a -> Bool) -> [a] -> [Int]
- genericDrop :: Integral i => i -> [a] -> [a]
- genericIndex :: Integral i => [a] -> i -> a
- genericReplicate :: Integral i => i -> a -> [a]
- genericSplitAt :: Integral i => i -> [a] -> ([a], [a])
- genericTake :: Integral i => i -> [a] -> [a]
- insertBy :: (a -> a -> Ordering) -> a -> [a] -> [a]
- intersect :: Eq a => [a] -> [a] -> [a]
- intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- isInfixOf :: Eq a => [a] -> [a] -> Bool
- isSuffixOf :: Eq a => [a] -> [a] -> Bool
- stripPrefix :: Eq a => [a] -> [a] -> Maybe [a]
- subsequences :: [a] -> [[a]]
- union :: Eq a => [a] -> [a] -> [a]
- unionBy :: (a -> a -> Bool) -> [a] -> [a] -> [a]
- unzip4 :: [(a, b, c, d)] -> ([a], [b], [c], [d])
- unzip5 :: [(a, b, c, d, e)] -> ([a], [b], [c], [d], [e])
- unzip6 :: [(a, b, c, d, e, f)] -> ([a], [b], [c], [d], [e], [f])
- unzip7 :: [(a, b, c, d, e, f, g)] -> ([a], [b], [c], [d], [e], [f], [g])
- zip4 :: [a] -> [b] -> [c] -> [d] -> [(a, b, c, d)]
- zip5 :: [a] -> [b] -> [c] -> [d] -> [e] -> [(a, b, c, d, e)]
- zip6 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [(a, b, c, d, e, f)]
- zip7 :: [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [(a, b, c, d, e, f, g)]
- isSubsequenceOf :: Eq a => [a] -> [a] -> Bool
- compareLength :: [a] -> Int -> Ordering
- inits1 :: [a] -> [NonEmpty a]
- tails1 :: [a] -> [NonEmpty a]
Documentation
Instances
MonadZip [] | |||||
Defined in Control.Monad.Zip | |||||
Eq1 [] | |||||
Defined in Data.Functor.Classes | |||||
Ord1 [] | |||||
Defined in Data.Functor.Classes Methods liftCompare :: (a -> b -> Ordering) -> [a] -> [b] -> Ordering | |||||
Read1 [] | |||||
Defined in Data.Functor.Classes Methods liftReadsPrec :: (Int -> ReadS a) -> ReadS [a] -> Int -> ReadS [a] liftReadList :: (Int -> ReadS a) -> ReadS [a] -> ReadS [[a]] liftReadPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [a] liftReadListPrec :: ReadPrec a -> ReadPrec [a] -> ReadPrec [[a]] | |||||
Show1 [] | |||||
Defined in Data.Functor.Classes | |||||
Alternative [] | |||||
Defined in GHC.Internal.Base | |||||
Applicative [] | |||||
Functor [] | |||||
Defined in GHC.Internal.Base | |||||
Monad [] | |||||
MonadPlus [] | |||||
Defined in GHC.Internal.Base | |||||
MonadFail [] | |||||
Defined in GHC.Internal.Control.Monad.Fail | |||||
Foldable [] | |||||
Defined in GHC.Internal.Data.Foldable Methods fold :: Monoid m => [m] -> m # foldMap :: Monoid m => (a -> m) -> [a] -> m # foldMap' :: Monoid m => (a -> m) -> [a] -> m # foldr :: (a -> b -> b) -> b -> [a] -> b # foldr' :: (a -> b -> b) -> b -> [a] -> b # foldl :: (b -> a -> b) -> b -> [a] -> b # foldl' :: (b -> a -> b) -> b -> [a] -> b # foldr1 :: (a -> a -> a) -> [a] -> a # foldl1 :: (a -> a -> a) -> [a] -> a # elem :: Eq a => a -> [a] -> Bool # maximum :: Ord a => [a] -> a # | |||||
Traversable [] | |||||
Defined in GHC.Internal.Data.Traversable | |||||
Generic1 [] | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
IsChar c => PrintfArg [c] | |||||
Defined in Text.Printf | |||||
IsChar c => PrintfType [c] | |||||
Defined in Text.Printf | |||||
Monoid [a] | |||||
Semigroup [a] | |||||
a ~ Char => IsString [a] | |||||
Defined in GHC.Internal.Data.String Methods fromString :: String -> [a] # | |||||
Generic [a] | |||||
Defined in GHC.Internal.Generics Associated Types
| |||||
IsList [a] | |||||
Defined in GHC.Internal.IsList Associated Types
| |||||
Read a => Read [a] | |||||
Show a => Show [a] | |||||
Eq a => Eq [a] | |||||
Ord a => Ord [a] | |||||
type Rep1 [] | |||||
Defined in GHC.Internal.Generics type Rep1 [] = D1 ('MetaData "List" "GHC.Types" "ghc-prim" 'False) (C1 ('MetaCons "[]" 'PrefixI 'False) (U1 :: Type -> Type) :+: 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 [a] | |||||
Defined in GHC.Internal.Generics type Rep [a] = D1 ('MetaData "List" "GHC.Types" "ghc-prim" 'False) (C1 ('MetaCons "[]" 'PrefixI 'False) (U1 :: Type -> Type) :+: 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 [a] | |||||
Defined in GHC.Internal.IsList type Item [a] = a |
intersperse :: a -> [a] -> [a] #
permutations :: [a] -> [[a]] #
isPrefixOf :: Eq a => [a] -> [a] -> Bool #
intercalate :: [a] -> [[a]] -> [a] #
mapAccumL :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b) #
mapAccumR :: Traversable t => (s -> a -> (s, b)) -> s -> t a -> (s, t b) #
genericLength :: Num i => [a] -> i #
zipWith7 :: (a -> b -> c -> d -> e -> f -> g -> h) -> [a] -> [b] -> [c] -> [d] -> [e] -> [f] -> [g] -> [h] #
deleteFirstsBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #
dropWhileEnd :: (a -> Bool) -> [a] -> [a] #
elemIndices :: Eq a => a -> [a] -> [Int] #
findIndices :: (a -> Bool) -> [a] -> [Int] #
genericDrop :: Integral i => i -> [a] -> [a] #
genericIndex :: Integral i => [a] -> i -> a #
genericReplicate :: Integral i => i -> a -> [a] #
genericSplitAt :: Integral i => i -> [a] -> ([a], [a]) #
genericTake :: Integral i => i -> [a] -> [a] #
intersectBy :: (a -> a -> Bool) -> [a] -> [a] -> [a] #
isSuffixOf :: Eq a => [a] -> [a] -> Bool #
stripPrefix :: Eq a => [a] -> [a] -> Maybe [a] #
subsequences :: [a] -> [[a]] #
isSubsequenceOf :: Eq a => [a] -> [a] -> Bool #
compareLength :: [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 [] 0
EQ>>>
compareLength [] 1
LT>>>
compareLength ['a'] 1
EQ>>>
compareLength ['a', 'b'] 1
GT>>>
compareLength [0..] 100
GT>>>
compareLength undefined (-1)
GT>>>
compareLength ('a' : undefined) 0
GT
Since: 4.21.0.0
inits1 :: [a] -> [NonEmpty a] Source #
The inits1
function returns all non-empty initial segments of the
argument, shortest first.
Laziness
Note that inits1
has the following strictness property:
inits1 (xs ++ _|_) = inits1 xs ++ _|_
In particular,
inits1 _|_ = _|_
Examples
>>>
inits1 "abc"
['a' :| "",'a' :| "b",'a' :| "bc"]
>>>
inits1 []
[]
inits1 is productive on infinite lists:
>>>
take 3 $ inits1 [1..]
[1 :| [],1 :| [2],1 :| [2,3]]
Since: 4.21.0.0
tails1 :: [a] -> [NonEmpty a] Source #
\(\mathcal{O}(n)\). The tails1
function returns all non-empty final
segments of the argument, longest first.
Laziness
Note that tails1
has the following strictness property:
tails1 _|_ = _|_
>>>
tails1 undefined
*** Exception: Prelude.undefined
>>>
drop 1 (tails1 [undefined, 1, 2])
[1 :| [2],2 :| []]
Examples
>>>
tails1 "abc"
['a' :| "bc",'b' :| "c",'c' :| ""]
>>>
tails1 [1, 2, 3]
[1 :| [2,3],2 :| [3],3 :| []]
>>>
tails1 []
[]
Since: 4.21.0.0