UNPKG

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