UNPKG

1.65 kBJavaScriptView Raw
1var _curry1 =
2/*#__PURE__*/
3require("./internal/_curry1");
4
5var _isArguments =
6/*#__PURE__*/
7require("./internal/_isArguments");
8
9var _isArray =
10/*#__PURE__*/
11require("./internal/_isArray");
12
13var _isObject =
14/*#__PURE__*/
15require("./internal/_isObject");
16
17var _isString =
18/*#__PURE__*/
19require("./internal/_isString");
20/**
21 * Returns the empty value of its argument's type. Ramda defines the empty
22 * value of Array (`[]`), Object (`{}`), String (`''`), and Arguments. Other
23 * types are supported if they define `<Type>.empty`,
24 * `<Type>.prototype.empty` or implement the
25 * [FantasyLand Monoid spec](https://github.com/fantasyland/fantasy-land#monoid).
26 *
27 * Dispatches to the `empty` method of the first argument, if present.
28 *
29 * @func
30 * @memberOf R
31 * @since v0.3.0
32 * @category Function
33 * @sig a -> a
34 * @param {*} x
35 * @return {*}
36 * @example
37 *
38 * R.empty(Just(42)); //=> Nothing()
39 * R.empty([1, 2, 3]); //=> []
40 * R.empty('unicorns'); //=> ''
41 * R.empty({x: 1, y: 2}); //=> {}
42 */
43
44
45var empty =
46/*#__PURE__*/
47_curry1(function empty(x) {
48 return x != null && typeof x['fantasy-land/empty'] === 'function' ? x['fantasy-land/empty']() : x != null && x.constructor != null && typeof x.constructor['fantasy-land/empty'] === 'function' ? x.constructor['fantasy-land/empty']() : x != null && typeof x.empty === 'function' ? x.empty() : x != null && x.constructor != null && typeof x.constructor.empty === 'function' ? x.constructor.empty() : _isArray(x) ? [] : _isString(x) ? '' : _isObject(x) ? {} : _isArguments(x) ? function () {
49 return arguments;
50 }() : void 0 // else
51 ;
52});
53
54module.exports = empty;
\No newline at end of file