In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is Scala Coriarization". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn what Scala Corification is.
Corialization is a technique that transforms a function that accepts multiple parameters into a function that accepts a single parameter (the first parameter of the initial function) and returns a new function that accepts the remaining parameters and returns the result.
Let's first give a common non-Corialized function definition and implement an addition function:
Scala > def plainOldSum (XRU IntMagi YRO Int) = x + y
PlainOldSum: (X: Int, y: Int) Int
Scala > plainOldSum (1Jue 2)
Res0: Int = 3
Using the "Corialization" technique, the function is defined as a list of parameters:
Scala > def curriedSum (x:Int) (y:Int) = x + y
CurriedSum: (X: Int) (y: Int) Int
Scala > curriedSum (1) (2)
Res0: Int = 3
When you call curriedSum (1) (2), you are actually calling two ordinary functions (non-Corialized functions) in turn. The first call uses a parameter x, which returns a value of a function type, and the second time you use the parameter y to call the value of this function type. We use the following two separate definitions to simulate the curriedSum Corialized function:
First define the first function:
Scala > def first (x:Int) = (y:Int) = > x + y
First: (X: Int) Int = > Int
Then we call this function with argument 1 to generate the second function.
Scala > val second=first (1)
Second: Int = > Int =
Scala > second (2)
Res1: Int = 3
The definition of first,second demonstrates the process of calling the Corialization function, which itself has nothing to do with curriedSum, but we can use curriedSum to define second, as follows:
Scala > val >
OnePlus: Int = > Int =
The underscore "_" is used as a placeholder for the second parameter list, and the return value of this definition is a function that adds one to the called parameter when called.
Scala > onePlus (2)
Res2: Int = 3
With Corialization, you can also define several onePlus-like functions, such as twoPlus
Scala > val twoPlus = curriedSum (2) _
TwoPlus: Int = > Int =
Scala > twoPlus (2)
Res3: Int = 4
Thank you for your reading, the above is the content of "what is Scala Coriarization", after the study of this article, I believe you have a deeper understanding of what Scala Coriarization is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.