HORIZON HASKELLDocslts/ghc-9.14.xd82dee82026-10-12Search names, modules, packages, or :: a typeCtrl K

GHC 9.14.1 · lts/ghc-9.14.x · d82dee8 · 2026-10-12

Moduleral-0.2.2Haskell2010

Data.RAList.NonEmpty

Non-empty random access list.

This module is designed to imported qualifed.

  • 2 types
  • 24 values
  • Packageral-0.2.2
  • Exports26
  • LanguageHaskell2010
  • LicenceGPL-2.0-or-later
  • SourceNonEmpty.hs
newtypenewtype NERAList a
#

Non-empty random access list.

Constructors

Instances19Functor, Foldable, Traversable, Foldable1, Arbitrary1, Traversable1, …
datadata NERAList' (f :: Type -> Type) a
#

Non-empty random access list, underlying representation.

The structure doesn't need to be hidden, as polymorphic recursion of Nodes starting from Leaf keeps the NERAList values well-formed.

Constructors

Instances10Functor, Foldable, Traversable, Foldable1, Traversable1, Eq, …

Showing

2 declarations

Construction

2 declarations

Indexing

8 declarations
value(!) :: NERAList a -> Int -> a
#

List index.

Example1 expression
fromNonEmpty ('a' :| ['b'..'f']) ! 0'a'
Example1 expression
fromNonEmpty ('a' :| ['b'..'f']) ! 5'f'
Example1 expression
fromNonEmpty ('a' :| ['b'..'f']) ! 6*** Exception: array index out of range: NERAList...
value(!?) :: NERAList a -> Int -> Maybe a
#

safe list index.

Example1 expression
fromNonEmpty ('a' :| ['b'..'f']) !? 0Just 'a'
Example1 expression
fromNonEmpty ('a' :| ['b'..'f']) !? 5Just 'f'
Example1 expression
fromNonEmpty ('a' :| ['b'..'f']) !? 6Nothing
valuehead :: NERAList a -> a
#

First value, head of the list.

Example1 expression
head $ fromNonEmpty $ 'a' :| ['b'..'f']'a'
valuelast :: NERAList a -> a
#

Last value of the list

Example1 expression
last $ fromNonEmpty $  'a' :| ['b'..'f']'f'
valueuncons :: NERAList a -> (a, RAList a)
#
Example1 expression
uncons $ fromNonEmpty $ 'a' :| "bcdef"('a',fromList "bcdef")
valuetail :: NERAList a -> RAList a
#

Tail of non-empty list can be empty.

Example1 expression
tail $ fromNonEmpty $ 'a' :| "bcdef"fromList "bcdef"

Conversions

2 declarations
valuefromNonEmpty :: NonEmpty a -> NERAList a
#
Example1 expression
fromNonEmpty ('a' :| ['b'..'f'])fromNonEmpty ('a' :| "bcdef")
Example1 expression
explicitShow (fromNonEmpty ('a' :| ['b'..'f']))"NE (Cons0 (Cons1 (Nd (Lf 'a') (Lf 'b')) (Last (Nd (Nd (Lf 'c') (Lf 'd')) (Nd (Lf 'e') (Lf 'f'))))))"

Folding

5 declarations
valueifoldMap1 :: Semigroup s => (Int -> a -> s) -> NERAList a -> s
#
Example1 expression
import Data.Semigroup (Min (..))
Example1 expression
ifoldMap1 (\_ x -> Min x) $ fromNonEmpty $ 5 :| [3,1,2,4]Min {getMin = 1}
Example1 expression
ifoldMap1 (\i x -> Min (i + x)) $ fromNonEmpty $ 5 :| [3,1,2,4]Min {getMin = 3}

Mapping

5 declarations
valueadjust :: Int -> (a -> a) -> NERAList a -> NERAList a
#

Adjust a value in the list.

Example1 expression
adjust 3 toUpper $ fromNonEmpty $ 'a' :| "bcdef"fromNonEmpty ('a' :| "bcDef")

If index is out of bounds, the list is returned unmodified.

Example1 expression
adjust 10 toUpper $ fromNonEmpty $ 'a' :| "bcdef"fromNonEmpty ('a' :| "bcdef")
Example1 expression
adjust (-1) toUpper $ fromNonEmpty $ 'a' :| "bcdef"fromNonEmpty ('a' :| "bcdef")
valuemap :: (a -> b) -> NERAList a -> NERAList b
#
Example1 expression
map toUpper (fromNonEmpty ('a' :| ['b'..'f']))fromNonEmpty ('A' :| "BCDEF")
valueimap :: (Int -> a -> b) -> NERAList a -> NERAList b
#
Example1 expression
imap (,) (fromNonEmpty ('a' :| ['b'..'f']))fromNonEmpty ((0,'a') :| [(1,'b'),(2,'c'),(3,'d'),(4,'e'),(5,'f')])