https://github.com/fccm2/cart-prod
Mapping functions on 2 input lists, based on cartesian-product comparision of their elements.
https://github.com/fccm2/cart-prod
Last synced: 11 months ago
JSON representation
Mapping functions on 2 input lists, based on cartesian-product comparision of their elements.
- Host: GitHub
- URL: https://github.com/fccm2/cart-prod
- Owner: fccm2
- License: other
- Created: 2025-06-07T13:53:15.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-06-07T14:04:18.000Z (12 months ago)
- Last Synced: 2025-06-07T14:35:15.757Z (12 months ago)
- Language: OCaml
- Size: 0 Bytes
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: License.txt
Awesome Lists containing this project
README
Mapping, and eventually filtering and folding, 2 input lists
based on the comparision of their elements as a cartesian-product,
and while preserving their original structure.
So the function:
```ocaml
val cart_prod_map :
('a -> 'b -> 'a * 'b) -> 'a list -> 'b list -> 'a list * 'b list
```
Used like this:
```ocaml
let chars = ['A'; 'B'; 'C']
let nums = [1; 2; 3; 4]
let cs, ns =
cart_prod_map (fun c n ->
if (c, n) = ('A', 3)
then ('a', 30)
else (c, n)
) chars nums
```
will return:
```ocaml
val cs : char list = ['a'; 'B'; 'C']
val ns : int list = [1; 2; 30; 4]
```