简体   繁体   中英

Currying Functions in Scala

I am new to Scala and I just started learning it and now trying some exercises. 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. 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"
  • [A, B, C] will deal with 3 different types
  • (f it will receive an argument that we'll name "f"
  • : (A, B) => C) that argument is type "function that takes A,B and returns C"
  • : A => (B => C) "curry" returns type "function that takes A and returns function that takes B and returns C"
  • = here's the "curry" code
  • 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()"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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