1 | var _curry3 =
|
---|
2 | /*#__PURE__*/
|
---|
3 | require("./internal/_curry3.js");
|
---|
4 | /**
|
---|
5 | * Creates a new list out of the two supplied by applying the function to each
|
---|
6 | * equally-positioned pair in the lists. The returned list is truncated to the
|
---|
7 | * length of the shorter of the two input lists.
|
---|
8 | *
|
---|
9 | * @function
|
---|
10 | * @memberOf R
|
---|
11 | * @since v0.1.0
|
---|
12 | * @category List
|
---|
13 | * @sig ((a, b) -> c) -> [a] -> [b] -> [c]
|
---|
14 | * @param {Function} fn The function used to combine the two elements into one value.
|
---|
15 | * @param {Array} list1 The first array to consider.
|
---|
16 | * @param {Array} list2 The second array to consider.
|
---|
17 | * @return {Array} The list made by combining same-indexed elements of `list1` and `list2`
|
---|
18 | * using `fn`.
|
---|
19 | * @example
|
---|
20 | *
|
---|
21 | * const f = (x, y) => {
|
---|
22 | * // ...
|
---|
23 | * };
|
---|
24 | * R.zipWith(f, [1, 2, 3], ['a', 'b', 'c']);
|
---|
25 | * //=> [f(1, 'a'), f(2, 'b'), f(3, 'c')]
|
---|
26 | * @symb R.zipWith(fn, [a, b, c], [d, e, f]) = [fn(a, d), fn(b, e), fn(c, f)]
|
---|
27 | */
|
---|
28 |
|
---|
29 |
|
---|
30 | var zipWith =
|
---|
31 | /*#__PURE__*/
|
---|
32 | _curry3(function zipWith(fn, a, b) {
|
---|
33 | var rv = [];
|
---|
34 | var idx = 0;
|
---|
35 | var len = Math.min(a.length, b.length);
|
---|
36 |
|
---|
37 | while (idx < len) {
|
---|
38 | rv[idx] = fn(a[idx], b[idx]);
|
---|
39 | idx += 1;
|
---|
40 | }
|
---|
41 |
|
---|
42 | return rv;
|
---|
43 | });
|
---|
44 |
|
---|
45 | module.exports = zipWith; |
---|