UNPKG

1.95 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2");
4
5var _isArray =
6/*#__PURE__*/
7require("./internal/_isArray");
8
9var _isFunction =
10/*#__PURE__*/
11require("./internal/_isFunction");
12
13var _isString =
14/*#__PURE__*/
15require("./internal/_isString");
16
17var toString =
18/*#__PURE__*/
19require("./toString");
20/**
21 * Returns the result of concatenating the given lists or strings.
22 *
23 * Note: `R.concat` expects both arguments to be of the same type,
24 * unlike the native `Array.prototype.concat` method. It will throw
25 * an error if you `concat` an Array with a non-Array value.
26 *
27 * Dispatches to the `concat` method of the first argument, if present.
28 * Can also concatenate two members of a [fantasy-land
29 * compatible semigroup](https://github.com/fantasyland/fantasy-land#semigroup).
30 *
31 * @func
32 * @memberOf R
33 * @since v0.1.0
34 * @category List
35 * @sig [a] -> [a] -> [a]
36 * @sig String -> String -> String
37 * @param {Array|String} firstList The first list
38 * @param {Array|String} secondList The second list
39 * @return {Array|String} A list consisting of the elements of `firstList` followed by the elements of
40 * `secondList`.
41 *
42 * @example
43 *
44 * R.concat('ABC', 'DEF'); // 'ABCDEF'
45 * R.concat([4, 5, 6], [1, 2, 3]); //=> [4, 5, 6, 1, 2, 3]
46 * R.concat([], []); //=> []
47 */
48
49
50var concat =
51/*#__PURE__*/
52_curry2(function concat(a, b) {
53 if (_isArray(a)) {
54 if (_isArray(b)) {
55 return a.concat(b);
56 }
57
58 throw new TypeError(toString(b) + ' is not an array');
59 }
60
61 if (_isString(a)) {
62 if (_isString(b)) {
63 return a + b;
64 }
65
66 throw new TypeError(toString(b) + ' is not a string');
67 }
68
69 if (a != null && _isFunction(a['fantasy-land/concat'])) {
70 return a['fantasy-land/concat'](b);
71 }
72
73 if (a != null && _isFunction(a.concat)) {
74 return a.concat(b);
75 }
76
77 throw new TypeError(toString(a) + ' does not have a method named "concat" or "fantasy-land/concat"');
78});
79
80module.exports = concat;
\No newline at end of file