F # can synthesize several function groups into new functions

Source: Internet
Author: User

What C # can do, F # basically can do, but what F # can do, C # may not be able to do.

The functions in F # can be used to combine several functions. The following example combines the two functions of function1 and function2 into Funuoction3 with the operator ">>" (or "<<"), which can then be used Function3.

Let function1 x = x + 1

Let function2 x = x * 2

Let Function3 = function1 >> function2

Let RESULT5 = Function3 100

The result of the operation is 202.

Let's look at the following example:

Let AddOne x = x + 1
Let timestwo x = 2 * x

Let Compose1 = AddOne << timestwo
Let Compose2 = AddOne >> timestwo

The result is 5.
Let RESULT1 = Compose1 2

The result is 6.
Let result2 = Compose2 2

F # can synthesize several function groups into new 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.