# Generic zip function?

**URL:** <https://discuss.ocaml.org/t/generic-zip-function/14763>\
**Category:** Learning\
**Created:** [June 9, 2024, 8:48pm UTC](https://discuss.ocaml.org/t/generic-zip-function/14763 "2024-06-09T20:48:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Roman\_Funk](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/roman_funk/32/4699_2.png) [@Roman\_Funk](https://discuss.ocaml.org/u/Roman_Funk)\
**Post date:** [June 9, 2024, 8:48pm UTC](https://discuss.ocaml.org/t/generic-zip-function/14763/1 "2024-06-09T20:48:03Z")

</div>

Hello,  
I was dealing with another Euler task and I ended up writing this:

```ocaml
  match List.zip cypher keys with
  | Ok x -> List.map x ~f:(fun (a,b) -> a lxor b)
  | _ -> []

```

Is there zip function that takes a function which is applied to the resulting tuple instead of producing a tuple? In this code I assume, I iterate twice over the list.

I assume Haskell has such function: [**zip** :: Zip f =\> f a → f b → f (a, b)]

---

<div class="post-metadata">

**Author:** ![nojb](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nojb/32/519_2.png) [@nojb](https://discuss.ocaml.org/u/nojb)\
**Post date:** [June 9, 2024, 9:21pm UTC](https://discuss.ocaml.org/t/generic-zip-function/14763/2 "2024-06-09T21:21:58Z")

</div>

Have you looked at `List.map2 : ('a -> 'b -> 'c) -> 'a list -> 'b list -> 'c list`?

Cheers,  
Nicolas
