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