| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Euler.Util.List
Synopsis
- neTails :: NonEmpty a -> NonEmpty (NonEmpty a)
- sliding :: Int -> [a] -> [[a]]
- transpose :: [[a]] -> [[a]]
- untilNothing :: [Maybe a] -> [a]
- maximumOn :: Ord b => (a -> b) -> [a] -> a
- countDistinct :: (Ord a, Integral b) => [a] -> b
- mode :: Ord a => [a] -> a
- dedupe :: Eq a => [a] -> [a]
- adjustEach :: (a -> a) -> [a] -> [[a]]
- adjustIndex :: Int -> (a -> a) -> [a] -> [a]
Documentation
>>>import Data.Char (toUpper)
neTails :: NonEmpty a -> NonEmpty (NonEmpty a) Source #
Like tails, but only the non-empty tails from a non-empty list. The result is
non-empty because every non-empty list has at least one non-empy suffix
(itself).
>>>neTails (1 :| [])(1 :| []) :| []
>>>neTails ('a' :| "bc")('a' :| "bc") :| ['b' :| "c",'c' :| ""]
sliding :: Int -> [a] -> [[a]] Source #
Sublists of a fixed length.
>>>sliding 2 "abcd"["ab","bc","cd"]
>>>sliding 3 "abcde"["abc","bcd","cde"]
untilNothing :: [Maybe a] -> [a] Source #
>>>untilNothing [Just 1, Just 2, Nothing, Just 3][1,2]
countDistinct :: (Ord a, Integral b) => [a] -> b Source #
The number of unique elements in a list.
>>>countDistinct []0
>>>countDistinct "aaaaabaa"2
mode :: Ord a => [a] -> a Source #
The most common element in the list, assuming the list is nonempty and has a single most common element.
>>>mode "abbbbcc"'b'
dedupe :: Eq a => [a] -> [a] Source #
Remove consecutive duplicate elements from a list.
>>>dedupe [][]
>>>dedupe "abbbbcca""abca"
adjustEach :: (a -> a) -> [a] -> [[a]] Source #
>>>adjustEach toUpper "abc"["Abc","aBc","abC"]
>>>adjustEach id [][]
adjustIndex :: Int -> (a -> a) -> [a] -> [a] Source #
>>>adjustIndex 2 toUpper "abcd""abCd"