Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

DT Dreamworks lesson 27 practical Analysis of Type,Array,List,Tuple pattern matching

Shulou Source: shulou.com Published: 2022-06-03 03:34:14 10月04日 Update

Wang Jialin personally taught "DT big data Dream Factory" big data actual combat video Scala profound and simple actual combat classic (lecture 1-87) complete video, PPT, code download:

Baidu cloud disk: http://pan.baidu.com/s/1c0noOt6

Tencent Weiyun: http://url.cn/TnGbdC

360Cloud disk: http://yunpan.cn/cQ4c2UALDjSKy access password 45e2

Potato: http://www.tudou.com/programs/view/dHz5JKJxurM/

Youku: http://v.youku.com/v_show/id_XMTI4OTcwNzY2MA==.html?from=s1.8-1-1.2

Iqiyi: http://www.iqiyi.com/w_19rru5bi79.html#vfrm=2-3-0-1

Tencent Video: http://v.qq.com/boke/page/k/0/d/k016008s0rd.html

Technology enthusiasts, especially big data enthusiasts, can add the qq group of DT big data DreamWorks.

DT big data DreamWorks ①: 462923555

DT big data DreamWorks ②: 437123764

DT big data DreamWorks ③: 418110145

Wechat public account: DT_Spark

Mr. Wang Jialin's WeChat account: 18610086859

Mr. Wang Jialin QQ: 1740415547

Mr. Wang Jialin email: 18610086859@126.com

This video is explained by Mr. Wang Jialin in person, completely through the code to bring you to the era of people's data.

Package com.dt.scala.pattern_match/** * @ author iken * @ date 2015-08-29 * / object PatternMatchMore {def main (args: Array [String]) {/ * * 1. Match a variable of an unknown type to the corresponding type * this is so advanced that pattern matching can intelligently determine the type of content to be matched while the program is running * Note: Map does not specify its type because scala does pattern matching for interfaces and generics Scala erases the specific type * so uses the placeholder * / def match_type (t: Any) = t match {case p: Int = > println ("It is an integer!") Case p: String = > println ("It is an Integer!") Case m: Map [_, _] = > m.foreach (println) case _ = > println ("unknow type!")} match_type (2) match_type (Map ("Scala"-> "Spark")) / * * 2. Match an unknown array, which can match the array to a specific form of case * case1 means that the array has only one element, and the element must be 0 * case2, which means that the array has two arbitrary elements * case3 means that the data has any number of elements. And the first element must be 0 * / def match_array (arr: Any) = arr match {case Array (0) = > println ("Array" + "0") case Array (xonomy) = > println ("Array" + x + "" + y) case Array (0jurisdiction *) = > println ("Array" + "0...") Case _ = > println ("some thing!")} match_array (Array (0)) match_array (Array (0meme 1)) match_array (Array (0pime 1) 2 Jing 3)) match_array (Array ("hello", "world")) / * * 3. Match an unknown List, which can match the array to a specific form of case * case1 means that the List has only one element, and the element must be 0 * case2, which means that the List has two arbitrary elements * case3 means that the List has any number of elements. And the first element must be 0 * / def match_list (lst: Any) = lst match {case 0:: Nil = > println ("List" + "0") case x:: y:: Nil = > println ("List" + x + "" + y) case 0:: tail = > println ("List" + "0...") Case _ = > println ("some thing!")} match_list (List (0)) match_list (List (0meme 1)) match_list (List (0pime 1) 2 Jing 3 Jing 4) match_list (List ("hello", "world")) / * * 4. Match an unknown Tuple, which can match the array to a specific form of case * case1 means that the Tuple has only one element, and the element must be 0 * case2, which means that the Tuple has two arbitrary elements * case3 means that the Tuple has any number of elements. And the first element must be 0 * / def match_tuple (tuple: Any) = tuple match {case (0println _) = > println ("List" + "0") case (XMague _) = > println ("List" + x) case _ = > println ("some thing!")} match_tuple ((0, "scala")) match_tuple (("hello", 1) match_tuple ((0prit 1) 2pm 3)}}

Tags: Element data array factory Wang family type teacher video actual combat two only form pattern code enthusiast cloud disk Tencent advanced simple code download Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology MariaDB Linux Docker vpn