HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Modulerelude-1.2.0.0Haskell2010

Relude.List

SPDX-License-Identifier : MIT Maintainer : Kowainik xrom.xkov@gmail.com Stability : Stable Portability : Portable

Utility functions to work with lists and NonEmpty lists.

  • 3 values
  • Packagerelude-1.2.0.0
  • Exports3
  • LanguageHaskell2010
  • LicenceMIT
  • SourceList.hs

Most of the Data.List types and function.

Note, that list partial functions (e.g. head) are not exported from Data.List. Instead relude provides safe functions that work with NonEmpty. You can find them in the Relude.List.NonEmpty module instead.

Reexports from Data.List.NonEmpty and additional safe functions to work with list type in terms of NonEmpty.

value(!!?) :: [a] -> Int -> Maybe a
#

Safer version of !!, returns a Maybe.

Get element from list using index value starting from `0`.

Example1 expression
[] !!? 0Nothing
Example1 expression
["a", "b", "c"] !!? 3Nothing
Example1 expression
[1, 2, 3] !!? (-1)Nothing
Example1 expression
["a", "b", "c"] !!? 2Just "c"
valuemaybeAt :: Int -> [a] -> Maybe a
#

!!? with its arguments flipped.

Get element from list using index value starting from `0`.

Example1 expression
maybeAt 0 []Nothing
Example1 expression
maybeAt 3 ["a", "b", "c"]Nothing
Example1 expression
maybeAt (-1) [1, 2, 3]Nothing
Example1 expression
maybeAt 2 ["a", "b", "c"]Just "c"
valuepartitionWith :: (a -> Either b c) -> [a] -> ([b], [c])
#

Partitions a list based on the result of function which produces an Either value. List of all elements producing Left are extracted, in order, to the first element of the output tuple. Similarly, a list of all elements producing Right are extracted to the second element of output.

Example1 expression
:{ divideEvenOrShow :: Int -> Either Int String divideEvenOrShow n     | even n = Left $ n `div` 2     | otherwise = Right $ "Odd: " <> show n :}
Example1 expression
partitionWith divideEvenOrShow [1 .. 6]([1,2,3],["Odd: 1","Odd: 3","Odd: 5"])