Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Random access list.
This module is designed to imported qualifed.
Synopsis
- data RAList a
- explicitShow :: Show a => RAList a -> String
- explicitShowsPrec :: Show a => Int -> RAList a -> ShowS
- empty :: RAList a
- singleton :: a -> RAList a
- cons :: a -> RAList a -> RAList a
- (!) :: RAList a -> Int -> a
- (!?) :: RAList a -> Int -> Maybe a
- uncons :: RAList a -> Maybe (a, RAList a)
- length :: RAList a -> Int
- null :: RAList a -> Bool
- toList :: RAList a -> [a]
- fromList :: [a] -> RAList a
- ifoldMap :: Monoid m => ( Int -> a -> m) -> RAList a -> m
- adjust :: forall a. Int -> (a -> a) -> RAList a -> RAList a
- map :: (a -> b) -> RAList a -> RAList b
- imap :: ( Int -> a -> b) -> RAList a -> RAList b
- itraverse :: forall f a b. Applicative f => ( Int -> a -> f b) -> RAList a -> f ( RAList b)
Documentation
Random access list.
Instances
Showing
Construction
Indexing
(!?) :: RAList a -> Int -> Maybe a Source #
safe list index.
>>>
fromList ['a'..'f'] !? 0
Just 'a'
>>>
fromList ['a'..'f'] !? 5
Just 'f'
>>>
fromList ['a'..'f'] !? 6
Nothing
uncons :: RAList a -> Maybe (a, RAList a) Source #
>>>
uncons $ fromList []
Nothing
>>>
uncons $ fromList "abcdef"
Just ('a',fromList "bcdef")
Conversions
fromList :: [a] -> RAList a Source #
>>>
fromList ['a' .. 'f']
fromList "abcdef"
>>>
explicitShow $ fromList ['a' .. 'f']
"NonEmpty (NE (Cons0 (Cons1 (Nd (Lf 'a') (Lf 'b')) (Last (Nd (Nd (Lf 'c') (Lf 'd')) (Nd (Lf 'e') (Lf 'f')))))))"
Folding
Mapping
adjust :: forall a. Int -> (a -> a) -> RAList a -> RAList a Source #
Adjust a value in the list.
>>>
adjust 3 toUpper $ fromList "bcdef"
fromList "bcdEf"
If index is out of bounds, the list is returned unmodified.
>>>
adjust 10 toUpper $ fromList "bcdef"
fromList "bcdef"
>>>
adjust (-1) toUpper $ fromList "bcdef"
fromList "bcdef"
map :: (a -> b) -> RAList a -> RAList b Source #
>>>
map toUpper (fromList ['a'..'f'])
fromList "ABCDEF"