12.1 Generating Sequences

Source: Internet
Author: User

12.1 Generating Sequences

There are several ways to build a sequence, first look at our choice, the direct way is to implement the IEnumerator <T> interface, provide the current property, and the MoveNext method, move the enumerator object to the next element. This requires explicitly creating an object with mutable state, which is clearly a violation of the functional style. The usual practice is to hide the variability, providing a more declarative method of expressing the contents of the generated sequence, similar to the delay value used in the previous chapter. The explicit use of mutable states (for example, implementing caching) does not seem like a good functional style, but when we hide the variability in the lazy< ' t> type, we get a perfectly reasonable functional code.

In general, in functional programming, we can use higher-order functions. The F # Library provides a number of function processing sequences, but we only look at one example. As we'll see later, C # and F # have simple ways to generate sequences, and in C # we can use iterations where F # provides a general purpose sequence processing feature called a sequence expression (sequence expressions).

12.1 Generating Sequences

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.