Today we learned the For loop content under pattern matching. Let's start with the code combat perspective.
For (I<-list (1,2,3,4,5)) println (i)//is actually called by the foreach
for ([email protected]"Flink" <-List ("Hadoop", "Spark", "Flink")) println (index)//for parameter matching by individual name
For (language, "Hadoop") <-Set ("Scala", "Spark", "Java", "Hadoop")) println (language)//to match a parameter initialization
For ((K,v:int) <-List (("Spark", 5), ("Hadoop", "Bigdata")) println (v)//Match by type
Let's analyze each of them. The first one is familiar, looping through the elements. What we're going to say here is that we're actually using foreach in the loop.
def foreach[b] (f:a = B) {
var these = this
while (!these.isempty) {
F (These.head)
these = These.tail
}
}
Second, we assign index to alias Flink, match it by Alias, and then print. The use of this is also foreach:
def foreach[u] (f:a = U): Unit
Third, we initialize one of the key values and then pattern match through the initialized values. The use of this is also foreach:
def foreach[u] (f:a = U): Unit
Finally, we do pattern matching by defining the type of the key value, which is also used by foreach:
def foreach[u] (f:a = U): Unit
Share more of the Scala resources:
Baidu Cloud Disk: http://pan.baidu.com/s/1gd7133t
Micro Cloud Disk: http://share.weiyun.com/047efd6cc76d6c0cb21605cfaa88c416
360 Cloud Disk: Http://yunpan.cn/cQN9gvcKXe26M (extract code: 13CD)
Information from DT Big Data Dream Factory public account: Dt_spark
Follow the account for more information about Scala learning
75th: For loop under pattern matching