Scala Advanced Features-01

Source: Internet
Author: User

Goal one: In-depth understanding of higher order functions

  Higher order functions

1.1 Concepts

Scala mixes object-oriented and functional features,

We usually use an expression that can be passed as a parameter to a method called a function.

In functional programming languages, functions are "prime citizens",

Higher-order functions include: functions as Values , anonymous functions , closures , currying , and so on.

    1.2 function as a value (hence the name Incredibles: The value of the function as the return value)

    

    1.3 Anonymous functions

    In Scala, you don't need to give each function a name, and a function that doesn't assign a function to a variable is called an anonymous function.

    

Since Scala can automatically infer the type of parameters, it can be written to streamline some

    

Do you remember the magic underline? That's the way to end it.

    

    1.4 Converting a method into a function

In Scala, the difference between a method and a functional one is that the function can be

Pass the parameter to the method, but the method can not be converted into a function,

The Magic underline has appeared

    

    1.5 currying

    Currying refers to the process of turning a method that accepts two parameters into a new method of accepting a parameter.

First method: Def m (x:int) = (y:int) =>x*y

    

Second method: Def m (X:int) (Y:int) =x*y

    

  

The following section describes implicit conversions and hermit parameters

Merry Christmas

      

      

Scala Advanced Features-01

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.