Description
Provides zips with default values.
Description
Typical zip functions like zip
, zipWith
, and zipWith3
will stop with the shortest list exhausted. Consequently information is lost. This library solves this issue by inserting default values. The these
package serves a similar purpose but allows more than just lists to be zipped with the Align
type class. However, zipping several lists and using defaults is not as easy.
README.md
list-zip-def
Provides zip functions that use a given default value, whenever one list is exhausted, but not all.
Prelude> import Data.List.Zip
Prelude Data.List.Zip> zipDef 0 'x' [1, 2, 3] "a"
[(1,'a')(2,'x')(3,'x')]
The resulting list spine is also lazy:
Prelude Data.List.Zip> let xs = zipDef 0 'x' [1, 2, 3 :: Int] "a"
Prelude Data.List.Zip> :sprint xs
xs = _
Prelude Data.List.Zip> import Data.Maybe
Prelude Data.List.Zip Data.Maybe> listToMaybe xs
Just (1,'a')
Prelude Data.List.Zip Data.Maybe> :sprint xs
xs = (1,'a') : _