88th: Scala uses the for expression to implement map, FLATMAP, filter

Source: Internet
Author: User

Today we will learn how to use the for expression to implement map, Flatmap, and filter

First, let's look at the map. The function of map is to pass in a list, through a function f, to change the element A in list to the process of element B. Finally get the list formed by B. If this process is implemented by a For loop, the following actions are performed:

for (element <-list) yield f (Element)

Next we look at the Flatmap. The function of Flatmap is to pass in a list, through a function f, to convert each element of the list into a list, and finally to return a list of all the elements in those lists. This process, if implemented by the for expression, operates as follows: for (X<-list;y<-f (x)) yield y

Finally, we look at the filter operation, the function of filter is to pass in a list of lists, through the function F, filter out the Boolean expression is true, that is, the eligible elements, and finally return the list of elements that meet the criteria. This process, if implemented by the for expression, operates as follows: for (Elem <-list if f (elem)) yield Elem

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

88th: Scala uses the for expression to implement map, FLATMAP, filter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.