Safe Haskell | None |
---|---|
Language | Haskell2010 |
Grouped lists are like lists, but internally they are represented as groups of consecutive elements.
For example, the list [1,2,2,3,4,5,5,5]
would be internally
represented as [[1],[2,2],[3],[4],[5,5,5]]
. Use groupedGroups
to see this.
- data Grouped a
- empty :: Grouped a
- point :: Pointed p => forall a. a -> p a
- concatMap :: Eq b => Grouped a -> (a -> Grouped b) -> Grouped b
- replicate :: Int -> a -> Grouped a
- fromGroup :: Group a -> Grouped a
- length :: Foldable t => forall a. t a -> Int
- index :: Grouped a -> Int -> Maybe a
- adjust :: Eq a => (a -> a) -> Int -> Grouped a -> Grouped a
- adjustM :: (Monad m, Eq a) => (a -> m a) -> Int -> Grouped a -> m (Grouped a)
- take :: Int -> Grouped a -> Grouped a
- drop :: Int -> Grouped a -> Grouped a
- map :: Eq b => (a -> b) -> Grouped a -> Grouped b
- traverseGrouped :: (Applicative f, Eq b) => (a -> f b) -> Grouped a -> f (Grouped b)
- traverseGroupedByGroup :: (Applicative f, Eq b) => (Group a -> f (Grouped b)) -> Grouped a -> f (Grouped b)
- traverseGroupedByGroupAccum :: (Monad m, Eq b) => (acc -> Group a -> m (acc, Grouped b)) -> acc -> Grouped a -> m (acc, Grouped b)
- partition :: Eq a => (a -> Bool) -> Grouped a -> (Grouped a, Grouped a)
- filter :: Eq a => (a -> Bool) -> Grouped a -> Grouped a
- sort :: Ord a => Grouped a -> Grouped a
- zipWith :: Eq c => (a -> b -> c) -> Grouped a -> Grouped b -> Grouped c
- zip :: (Eq a, Eq b) => Grouped a -> Grouped b -> Grouped (a, b)
- fromList :: Eq a => [a] -> Grouped a
- data Group a
- buildGroup :: Int -> a -> Maybe (Group a)
- groupElement :: Group a -> a
- groupSize :: Group a -> Int
- groupedGroups :: Grouped a -> [Group a]
- firstGroup :: Grouped a -> Maybe (Group a, Grouped a)
- lastGroup :: Grouped a -> Maybe (Grouped a, Group a)
Type
Type of grouped lists. Grouped lists are finite lists that behave well in the abundance of sublists that have all their elements equal.
Foldable Grouped Source | |
Pointed Grouped Source | |
Eq a => IsList (Grouped a) Source | Method |
Eq a => Eq (Grouped a) Source | |
Show a => Show (Grouped a) Source | |
Eq a => Monoid (Grouped a) Source | |
NFData a => NFData (Grouped a) Source | |
type Item (Grouped a) = a Source |
Builders
concatMap :: Eq b => Grouped a -> (a -> Grouped b) -> Grouped b Source
Map a function that produces a grouped list for each element in a grouped list, then concat the results.
replicate :: Int -> a -> Grouped a Source
Replicate a single element the given number of times. If the given number is less or equal to zero, it produces an empty list.
Info
length :: Foldable t => forall a. t a -> Int
Returns the size/length of a finite structure as an Int
. The
default implementation is optimized for structures that are similar to
cons-lists, because there is no general way to do better.
Indexing
index :: Grouped a -> Int -> Maybe a Source
Retrieve the element at the given index. If the index is
out of the list index range, it returns Nothing
.
adjust :: Eq a => (a -> a) -> Int -> Grouped a -> Grouped a Source
Update the element at the given index. If the index is out of range, the original list is returned.
Sublists
take :: Int -> Grouped a -> Grouped a Source
Take the given number of elements from the left end of the list.
drop :: Int -> Grouped a -> Grouped a Source
Discard the given number of elements from the left end of the list.
Mapping
map :: Eq b => (a -> b) -> Grouped a -> Grouped b Source
Apply a function to every element in a grouped list.
Traversal
traverseGrouped :: (Applicative f, Eq b) => (a -> f b) -> Grouped a -> f (Grouped b) Source
Apply a function with results residing in an applicative functor to every element in a grouped list.
traverseGroupedByGroup :: (Applicative f, Eq b) => (Group a -> f (Grouped b)) -> Grouped a -> f (Grouped b) Source
Similar to traverseGrouped
, but instead of applying a function to every element
of the list, it is applied to groups of consecutive elements. You might return more
than one element, so the result is of type Grouped
. The results are then concatenated
into a single value, embedded in the applicative functor.
traverseGroupedByGroupAccum Source
:: (Monad m, Eq b) | |
=> (acc -> Group a -> m (acc, Grouped b)) | |
-> acc | Initial value of the accumulator. |
-> Grouped a | |
-> m (acc, Grouped b) |
Like traverseGroupedByGroup
, but carrying an accumulator.
Note the Monad
constraint instead of Applicative
.
Filtering
partition :: Eq a => (a -> Bool) -> Grouped a -> (Grouped a, Grouped a) Source
Break a grouped list in the elements that match a given condition and those that don't.
filter :: Eq a => (a -> Bool) -> Grouped a -> Grouped a Source
Filter a grouped list by keeping only those elements that match a given condition.
Sorting
Zipping
zipWith :: Eq c => (a -> b -> c) -> Grouped a -> Grouped b -> Grouped c Source
Combine two lists using a combining function. If one list is longer, remaining elements are discarded.
zip :: (Eq a, Eq b) => Grouped a -> Grouped b -> Grouped (a, b) Source
Combine two lists in a single list of pairs. If one list is longer, remaining elements are discarded.
List conversion
For to-list conversion use toList
.
fromList :: Eq a => [a] -> Grouped a Source
Build a grouped list from a regular list. It doesn't work if the input list is infinite.
Groups
A Group
is a non-empty finite list that contains the same element
repeated a number of times.
Monad Group Source | |
Functor Group Source | |
Applicative Group Source | |
Foldable Group Source | |
Pointed Group Source | |
Eq a => Eq (Group a) Source | |
Ord a => Ord (Group a) Source | A group is larger than other if its constituent element is larger. If they are equal, the group with more elements is the larger. |
Show a => Show (Group a) Source | |
NFData a => NFData (Group a) Source |
buildGroup :: Int -> a -> Maybe (Group a) Source
Build a group by repeating the given element a number of times.
If the given number is less or equal to 0, Nothing
is returned.
groupElement :: Group a -> a Source
Get the element of a group.
In grouped lists
groupedGroups :: Grouped a -> [Group a] Source
Groups of consecutive elements in a grouped list.