source: node_modules/ramda/es/concat.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.8 KB
Line 
1import _curry2 from "./internal/_curry2.js";
2import _isArray from "./internal/_isArray.js";
3import _isFunction from "./internal/_isFunction.js";
4import _isString from "./internal/_isString.js";
5import 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
35var 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
65export default concat;
Note: See TracBrowser for help on using the repository browser.