utility-ht-0.0.16: Various small helper functions for Lists, Maybes, Tuples, Functions
Safe HaskellSafe-Inferred




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

Make a list as long as another one

\(Shape xs) (List ys) -> Match.take xs ys == List.take (length xs) ys

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

Drop as many elements as the first list is long

\(Shape xs) (List ys) -> Match.drop xs ys == List.drop (length xs) ys
\(Shape xs) (List ys) -> Match.take xs ys ++ Match.drop xs ys == ys

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

\(Shape xs) (List ys) -> Match.splitAt xs ys == (Match.take xs ys, Match.drop xs ys)
\(Shape xs) (List ys) -> Match.splitAt xs ys == List.splitAt (length xs) ys

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

\(Shape xs) (List ys) -> Match.takeRev xs ys == reverse (Match.take xs (reverse ys))

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

\(Shape xs) (List ys) -> Match.dropRev xs ys == reverse (Match.drop xs (reverse ys))

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

Specialisation of $>.

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

Check whether two lists with different element types have equal length. It holds

\(Shape xs) (List ys) -> equalLength xs ys == (length xs == length ys)

but equalLength is more efficient.

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

Compare the length of two lists over different types. It holds

\(Shape xs) (List ys) -> compareLength xs ys == compare (length xs) (length ys)

but compareLength is more efficient.

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

lessOrEqualLength x y is almost the same as compareLength x y <= EQ, but

>>> lessOrEqualLength "" undefined

whereas compareLength [] undefined <= EQ = undefined.

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

Returns the shorter one of two lists. It works also for infinite lists as much as possible. E.g.

>>> shorterList (shorterList (repeat 'a') (repeat 'b')) "abc"

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.