Scala Classic 87th: Using a for expression in Scala to make a query

Source: Internet
Author: User

for (generator; definition; filter) to Do data filtering query

Package Com.dt.scala.forexpression


Case Class Book (title:string, Authors:list[string])

Object For_query {


def main (args:array[string]) {

Val Books:list[book] = List (

Book ("Structure and Interpretation", List ("Abelson, Harold", "Sussman"),

Book ("Principles of Compiler Design",

List ("Aho, Alfred", "Ullman, Jeffrey")),

Book ("Programming in Modula-2", List ("Wirth, Niklaus")),

Book ("Introduction to Functional Programming", List ("Bird, Richard")),

Book ("The Java Language specification",

List ("Gosling, James", "Joy, Bill", "Steele, Guy", "Bracha, Gilad")))

Val result = for (b <-Books; a <-b.authors if a StartsWith "gosling") yield b.title

Val result = for (b <-Books if (B.title indexOf "Programming") >= 0) yield B.title

println (Result)

}


}


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 Classic 87th: Using a for expression in Scala to make a query

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.