Skip to content

Instantly share code, notes, and snippets.

@kadirmalak
Last active December 28, 2019 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadirmalak/4ef5318f0d63e0d753aa889b758c8f34 to your computer and use it in GitHub Desktop.
Save kadirmalak/4ef5318f0d63e0d753aa889b758c8f34 to your computer and use it in GitHub Desktop.
currying-demo-2
// notice the visual separation between the group of arguments
def testSomething2(something: String)(var1: Double, var2: String) = {
println(something + ", var1: " + var1 + ", var2: " + var2)
}
// here also the visual separation tells that the first two arguments (the data)
// is something different from the last argument (function to be called with the data)
def runWithVariations2(p1s: List[Int], p2s: List[String])(f: (Double, String) => Unit) = {
for (p1 <- p1s;
p2 <- p2s) {
f(p1, p2)
}
}
// testSomething2("some string") returns a function that takes 2 arguments, no need for a lambda func
runWithVariations2(List(1, 2, 3), List("a", "b", "c"))(testSomething2("some string"))
// and there is even a better way to call this function
// in the code below, you can clearly see that something is done in a scope
runWithVariations2(List(1, 2, 3), List("a", "b", "c")){
testSomething2("some string")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment