简体   繁体   English

Scala中的Curry函数

[英]Currying Functions in Scala

I am new to Scala and I just started learning it and now trying some exercises. 我是Scala的新手,我刚刚开始学习它,现在尝试一些练习。 This one in particular I have a trouble understanding. 特别是我对此很难理解。

I understand up to the (f: (A, B) => C) part, but the rest I dont quite get it. 我了解(f: (A, B) => C)部分,但其余部分我不太明白。 Can someone please explain what's happening after the anonymous function part? 有人可以解释匿名功能部分之后发生了什么吗?

Thanks! 谢谢!

This is the function: 这是功能:

def curry[A, B, C](f: (A, B) => C): A => (B => C) = a => b => f(a, b)
  • def curry a method named "curry" def curry一种名为“ curry”的方法
  • [A, B, C] will deal with 3 different types [A, B, C]将处理3种不同的类型
  • (f it will receive an argument that we'll name "f" (f会收到一个参数,我们将其命名为“ f”
  • : (A, B) => C) that argument is type "function that takes A,B and returns C" : (A, B) => C) ,该参数为类型“接受A,B并返回C的函数”
  • : A => (B => C) "curry" returns type "function that takes A and returns function that takes B and returns C" : A => (B => C) “ curry”返回类型“带A并返回带B并返回C的函数”
  • = here's the "curry" code =这是“ curry”代码
  • a => b => f(a, b) function that takes an argument (we'll call "a") and returns a function that takes an argument (we'll call "b") that returns the value returned after "a" and "b" are passed to "f()" a => b => f(a, b)函数,该函数接受一个参数(我们称为“ a”)并返回一个函数,该函数接受一个参数(我们称为“ b”),该函数返回在“ a”和“ b”传递给“ f()”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM