Data.List.Match

utility-ht-0.0.12: Various small helper functions for Lists, Maybes, Tuples, Functions

Safe Haskell | Safe
Language | Haskell98

Data.List.Match

Synopsis

- take :: [b] -> [a] -> [a]
- drop :: [b] -> [a] -> [a]
- splitAt :: [b] -> [a] -> ([a], [a])
- takeRev :: [b] -> [a] -> [a]
- dropRev :: [b] -> [a] -> [a]
- replicate :: [a] -> b -> [b]
- equalLength :: [a] -> [b] -> Bool
- compareLength :: [a] -> [b] -> Ordering
- lessOrEqualLength :: [a] -> [b] -> Bool
- shorterList :: [a] -> [a] -> [a]

# Documentation

take :: [b] -> [a] -> [a] #

Make a list as long as another one

drop :: [b] -> [a] -> [a] #

Drop as many elements as the first list is long

splitAt :: [b] -> [a] -> ([a], [a]) #

takeRev :: [b] -> [a] -> [a] #

dropRev :: [b] -> [a] -> [a] #

replicate :: [a] -> b -> [b] #

Specialisation of `$>`.

equalLength :: [a] -> [b] -> Bool #

Check whether two lists with different element types have equal length. It is equivalent to `length xs == length ys` but more efficient.

compareLength :: [a] -> [b] -> Ordering #

Compare the length of two lists over different types. It is equivalent to `(compare (length xs) (length ys))` but more efficient.

lessOrEqualLength :: [a] -> [b] -> Bool #

`lessOrEqualLength x y` is almost the same as `compareLength x y <= EQ`, but `lessOrEqualLength [] undefined = True`, whereas `compareLength [] undefined <= EQ = undefined`.

shorterList :: [a] -> [a] -> [a] #

Returns the shorter one of two lists. It works also for infinite lists as much as possible. E.g. `shorterList (shorterList (repeat 1) (repeat 2)) [1,2,3]` can be computed. The trick is, that the skeleton of the resulting list is constructed using `zipWith` without touching the elements. The contents is then computed (only) if requested.