📜  Lodash _.curry3() 方法

📅  最后修改于: 2022-05-13 01:56:29.070000             🧑  作者: Mango

Lodash _.curry3() 方法

Lodash _.curry3()方法返回给定函数的柯里化版本,但会柯里化三个参数,不多也不少。

句法:

_.curry3( fun )

参数:此方法采用上面列出并在下面讨论的单个参数。

  • fun:这是给定的函数。

返回值:它返回函数的柯里化版本。

注意:要执行以下示例,您必须使用此命令提示符安装lodash-contrib库并执行以下命令。

npm install lodash-contrib

示例 1:

Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(a, b, c){
    return a - b - c;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly 
// two arguments
console.log("Subtraction is :",
    gfgFunc(24)(22)(1));


Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(a, b, c){
    return a + b + c;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly 
// two arguments
console.log("Addition is :",
    gfgFunc(25)(23)(1));


Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y, z){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly
// three arguments
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2")("arg3"));


Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y, z){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly three
// arguments
// For two args, this method returns
// function info
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2"));


输出:

Subtraction is : 1

示例 2:

Javascript

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(a, b, c){
    return a + b + c;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly 
// two arguments
console.log("Addition is :",
    gfgFunc(25)(23)(1));

输出:

Addition is : 49

示例 3:

Javascript

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y, z){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly
// three arguments
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2")("arg3"));

输出:

Curried Arguments are : [Arguments] 
    { '0': 'arg1', '1': 'arg2', '2': 'arg3' }

示例 4:

Javascript

// Defining lodash contrib variable
var _ = require('lodash-contrib'); 
  
// Function
function fun(x, y, z){
    return arguments;
}
  
// Making curried function
var gfgFunc = _.curry3(fun);
  
// Only operates for exactly three
// arguments
// For two args, this method returns
// function info
console.log("Curried Arguments are :",
    gfgFunc("arg1")("arg2"));

输出:

[Function: mustBeUnary]