Scala's 89th-in-class classic: Using a for expression in Scala for insider thinking

Source: Internet
Author: User

The code jumps inside the for loop are map, withfilter, etc.

For is more direct than MAP,FILTER,FLATMAP, can be implemented with a for replacement


Package Com.dt.scala.forexpression


Object For_advanced {


def main (args:array[string]) {}

def Map[a, b] (list:list[a], f:a = b): list[b] =

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

def Flatmap[a, B] (list:list[a], f:a = List[b]): list[b] =

for (x <-list; y <-f (x)) yield y

def Filter[a] (list:list[a], f:a = Boolean): list[a] =

for (Elem <-list if f (elem)) yield Elem

}


DT Big Data Dream Factory public account: Dt_spark.

DT Big Data Dream Factory's public number is Dt_spark, every day will have big data actual combat video release, please continue to study.

Liaoliang DT Big Data dream factory Scala all videos, PPT and code in Baidu Cloud disk link:http://pan.baidu.com/share/home?uk=4013289088#category/type=0& Qq-pf-to=pcqq.group

QQ Group:

DT Big Data Dream Factory ①:462923555

DT Big Data Dream Factory ②: 437123764

DT Big Data Dream Factory ③:418110145



Scala's 89th-in-class classic: Using a for expression in Scala for insider thinking

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.