source: node_modules/ramda/src/of.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.1 KB
Line 
1var _curry2 =
2/*#__PURE__*/
3require("./internal/_curry2.js");
4/**
5 * Given a constructor and a value, returns a new instance of that constructor
6 * containing the value.
7 *
8 * Dispatches to the `fantasy-land/of` method of the constructor first (if present)
9 * or to the `of` method last (if present). When neither are present, wraps the
10 * value in an array.
11 *
12 * Note this `of` is different from the ES6 `of`; See
13 * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/of
14 *
15 * @func
16 * @memberOf R
17 * @since v0.3.0
18 * @category Function
19 * @sig (* -> {*}) -> a -> {a}
20 * @param {Object} Ctor A constructor
21 * @param {*} val any value
22 * @return {*} An instance of the `Ctor` wrapping `val`.
23 * @example
24 *
25 * R.of(Array, 42); //=> [42]
26 * R.of(Array, [42]); //=> [[42]]
27 * R.of(Maybe, 42); //=> Maybe.Just(42)
28 */
29
30
31var of =
32/*#__PURE__*/
33_curry2(function of(Ctor, val) {
34 return typeof Ctor['fantasy-land/of'] === 'function' ? Ctor['fantasy-land/of'](val) : typeof Ctor.of === 'function' ? Ctor.of(val) : [val];
35});
36
37module.exports = of;
Note: See TracBrowser for help on using the repository browser.