UNPKG

2.1 kBMarkdownView Raw
1Combines matching entries from maps.
2[:package:](https://www.npmjs.com/package/@extra-map/zip)
3[:smiley_cat:](https://github.com/orgs/nodef/packages?repo_name=extra-map)
4[:running:](https://npm.runkit.com/@extra-map/zip)
5[:vhs:](https://asciinema.org/a/339071)
6[:moon:](https://www.npmjs.com/package/@extra-map/zip.min)
7[:scroll:](https://unpkg.com/@extra-map/zip/)
8[:newspaper:](https://nodef.github.io/extra-map/)
9[:blue_book:](https://github.com/nodef/extra-map/wiki/)
10
11> Similar: [cartesianProduct], [zip].
12
13> This is part of package [extra-map].
14
15[extra-map]: https://www.npmjs.com/package/extra-map
16
17<br>
18
19```javascript
20map.zip(xs, [fm], [ft], [vd]);
21// xs: maps
22// fm: map function (vs, k)
23// ft: till function (dones) (some)
24// vd: default value
25```
26
27```javascript
28const map = require("extra-map");
29const array = require("extra-array");
30
31var x = new Map([["a", 1], ["b", 2], ["c", 3]]);
32var y = new Map([["a", 10], ["b", 20]]);
33map.zip([x, y]);
34// Map(2) { "a" => [ 1, 10 ], "b" => [ 2, 20 ] } (shortest)
35
36map.zip([x, y], ([a, b]) => a + b);
37// Map(2) { "a" => 11, "b" => 22 }
38
39map.zip([x, y], null, array.some);
40// Map(2) { "a" => [ 1, 10 ], "b" => [ 2, 20 ] } (shortest)
41
42map.zip([x, y], null, array.every, 0);
43// Map(3) { "a" => [ 1, 10 ], "b" => [ 2, 20 ], "c" => [ 3, 0 ] } (longest)
44```
45
46<br>
47<br>
48
49
50## References
51
52- [Data.List.zipWith: Haskell](http://hackage.haskell.org/package/base-4.12.0.0/docs/Data-List.html#v:zipWith)
53- [List-Extra.zip: elm](https://package.elm-lang.org/packages/elm-community/list-extra/7.1.0/List-Extra#zip)
54- [zip: Python](https://www.programiz.com/python-programming/methods/built-in/zip)
55- [itertools.zip_longest: Python](https://docs.python.org/3/library/itertools.html#itertools.zip_longest)
56- [zip: Ruby](https://apidock.com/ruby/Array/zip)
57- [_.zip: lodash](https://lodash.com/docs/4.17.15#zip)
58- [_.zipWith: lodash](https://lodash.com/docs/4.17.15#zipWith)
59- [Array.zip: sugarjs](https://sugarjs.com/docs/#/Array/zip)
60
61[cartesianProduct]: https://github.com/nodef/extra-map/wiki/cartesianProduct
62[zip]: https://github.com/nodef/extra-map/wiki/zip