The zip Function

Learn how the zip function can be used to combine multiple lists into a single one.

zip two lists into a list of pairs

Functions like map, filter, and fold have a limitation—they only work with a single list. What if we want to combine multiple lists?

In the functional paradigm, there is another powerful function abstraction called zip. One form of zip takes two input lists and returns a list of corresponding pairs. We can implement such a zip function in OCaml, as shown below:

Get hands-on with 1400+ tech skills courses.