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