euler-0.1.0.0

Safe HaskellSafe
LanguageHaskell2010

Euler.Util.List

Synopsis

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"]

transpose :: [[a]] -> [[a]] Source #

>>> transpose ["abc","def"]
["ad","be","cf"]

untilNothing :: [Maybe a] -> [a] Source #

>>> untilNothing [Just 1, Just 2, Nothing, Just 3]
[1,2]

maximumOn :: Ord b => (a -> b) -> [a] -> a Source #

maximumOn f is equivalent to maximumBy (compare `on' f), but is more efficient when f is costly.

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"