Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
Created December 28, 2019 15:52
Show Gist options
  • Select an option

  • Save kadirmalak/36bf49c1b31cf10b768b6d0d5db91de1 to your computer and use it in GitHub Desktop.

Select an option

Save kadirmalak/36bf49c1b31cf10b768b6d0d5db91de1 to your computer and use it in GitHub Desktop.
currying-1
def someFunc(a: Int, b: String, c: Double) = {
println("a: " + a + ", b: " + b + ", c: " + c)
}
someFunc(1, "str", 3.14) // we need all parameters to call it
// we're turning 3-arg function into 1-arg function
def someFuncCurried(a: Int, b: String) = {
def temp(c: Double) = {
someFunc(a, b, c) // a and b are remembered, only c is needed
}
temp _
}
val f = someFuncCurried(1, "str") // first 2 params saved
f(3.14) // now we can call using the third
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment