1 | import _curry1 from "./internal/_curry1.js";
|
---|
2 | import _isArguments from "./internal/_isArguments.js";
|
---|
3 | import _isArray from "./internal/_isArray.js";
|
---|
4 | import _isObject from "./internal/_isObject.js";
|
---|
5 | import _isString from "./internal/_isString.js";
|
---|
6 | import _isTypedArray from "./internal/_isTypedArray.js";
|
---|
7 | /**
|
---|
8 | * Returns the empty value of its argument's type. Ramda defines the empty
|
---|
9 | * value of Array (`[]`), Object (`{}`), String (`''`),
|
---|
10 | * TypedArray (`Uint8Array []`, `Float32Array []`, etc), and Arguments. Other
|
---|
11 | * types are supported if they define `<Type>.empty`,
|
---|
12 | * `<Type>.prototype.empty` or implement the
|
---|
13 | * [FantasyLand Monoid spec](https://github.com/fantasyland/fantasy-land#monoid).
|
---|
14 | *
|
---|
15 | * Dispatches to the `empty` method of the first argument, if present.
|
---|
16 | *
|
---|
17 | * @func
|
---|
18 | * @memberOf R
|
---|
19 | * @since v0.3.0
|
---|
20 | * @category Function
|
---|
21 | * @sig a -> a
|
---|
22 | * @param {*} x
|
---|
23 | * @return {*}
|
---|
24 | * @example
|
---|
25 | *
|
---|
26 | * R.empty(Just(42)); //=> Nothing()
|
---|
27 | * R.empty([1, 2, 3]); //=> []
|
---|
28 | * R.empty('unicorns'); //=> ''
|
---|
29 | * R.empty({x: 1, y: 2}); //=> {}
|
---|
30 | * R.empty(Uint8Array.from('123')); //=> Uint8Array []
|
---|
31 | */
|
---|
32 |
|
---|
33 | var empty =
|
---|
34 | /*#__PURE__*/
|
---|
35 | _curry1(function empty(x) {
|
---|
36 | 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 () {
|
---|
37 | return arguments;
|
---|
38 | }() : _isTypedArray(x) ? x.constructor.from('') : void 0 // else
|
---|
39 | ;
|
---|
40 | });
|
---|
41 |
|
---|
42 | export default empty; |
---|