6.4.41 using option types in C #

Source: Internet
Author: User

6.4.41 using option types in C #

Extension methods can write code that uses bindings and mappings in a smooth manner. Because the numbers in parentheses can be confusing, be aware that call Map is nested inside a lambda function as a parameter value for Bind:

Option<int> Readandadd () {

Returnreadinput (). Bind (n =

Readinput (). Map (m=> m + N));

}

In C #, the distinction between using higher-order functions and processing option types is more pronounced. C # does not directly support types such as differential unions, but the code becomes readable if the type can provide the appropriate handler function. Writing a functional program in C # is important to remember: while some of the underlying constructs may feel unnatural, because of the lambda function, you can write elegant function code in C # as well.

So far, we've discussed using higher-order functions to handle multivalued and optional values. In the previous chapter, we also talked about the last value is a function, and in the next section we will see that it is also very useful to handle the value of a function in higher-order functions.

6.4.41 using option types in C #

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.