[d24f17c] | 1 | import _curry1 from "./internal/_curry1.js";
|
---|
| 2 | import constructN from "./constructN.js";
|
---|
| 3 | /**
|
---|
| 4 | * Wraps a constructor function inside a curried function that can be called
|
---|
| 5 | * with the same arguments and returns the same type.
|
---|
| 6 | *
|
---|
| 7 | * @func
|
---|
| 8 | * @memberOf R
|
---|
| 9 | * @since v0.1.0
|
---|
| 10 | * @category Function
|
---|
| 11 | * @sig (* -> {*}) -> (* -> {*})
|
---|
| 12 | * @param {Function} fn The constructor function to wrap.
|
---|
| 13 | * @return {Function} A wrapped, curried constructor function.
|
---|
| 14 | * @see R.invoker
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * // Constructor function
|
---|
| 18 | * function Animal(kind) {
|
---|
| 19 | * this.kind = kind;
|
---|
| 20 | * };
|
---|
| 21 | * Animal.prototype.sighting = function() {
|
---|
| 22 | * return "It's a " + this.kind + "!";
|
---|
| 23 | * }
|
---|
| 24 | *
|
---|
| 25 | * const AnimalConstructor = R.construct(Animal)
|
---|
| 26 | *
|
---|
| 27 | * // Notice we no longer need the 'new' keyword:
|
---|
| 28 | * AnimalConstructor('Pig'); //=> {"kind": "Pig", "sighting": function (){...}};
|
---|
| 29 | *
|
---|
| 30 | * const animalTypes = ["Lion", "Tiger", "Bear"];
|
---|
| 31 | * const animalSighting = R.invoker(0, 'sighting');
|
---|
| 32 | * const sightNewAnimal = R.compose(animalSighting, AnimalConstructor);
|
---|
| 33 | * R.map(sightNewAnimal, animalTypes); //=> ["It's a Lion!", "It's a Tiger!", "It's a Bear!"]
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | var construct =
|
---|
| 37 | /*#__PURE__*/
|
---|
| 38 | _curry1(function construct(Fn) {
|
---|
| 39 | return constructN(Fn.length, Fn);
|
---|
| 40 | });
|
---|
| 41 |
|
---|
| 42 | export default construct; |
---|