12.3.2.1 using higher-order functions

Source: Internet
Author: User

12.3.2.1 using higher-order functions

In F #, using the Seq module is the same as list, and we already know how to use the LINQ extension method in C #. There is a significant difference in the use of lists and sequences: the sequence is deferred. The processing code is not executed until the element is fetched from the return sequence, although it does so only to return the result. Now, let's use a simple code snippet to illustrate:

var nums1 =

Nums. Where (n = n%3 = = 0)

. Select (n = n * N)

Let nums1 =

Nums |> Seq.filter (fun N-n%3=0)

|> Seq.map (fun n, n * N)

When we run this code, it does not process any elements; it only creates a sequence object that can be used to access the element; This also shows that the Nums value can be an infinite number sequence. If we only access the first 10 elements of the sequence, the code will work properly because both filtering and mapping are deferred processing data.

Using higher-order processing functions, you may already be familiar with the whole book, after we have discussed it in depth in the sixth chapter, we have provided many examples. In this chapter, we will turn to the methods that express the optional workflow.

12.3.2.1 using higher-order functions

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.