). It also includes an easy-to-use REPL for interactive development and analysis, just as with Python and R.I personally love Scala because it includes many practical programming features, such as pattern matching, and is considered much simpler than standard Java. However, using Scala to develop more than one method, this language as a feature to promote. It's a
would for other programs.This works because the trait application declares the main method with the appropriate signature and inherits it from the singleton object so that it can be used as a Scala program. The code between the braces is collected into the primary constructorof the Singleton object:Primary constructor, which is executed when the class is initialized.Inheriting from application is shorter than writing an explicit main method, but it a
Once an object is created, it will no longer change its contents, so that the object is immutable. This can be done without worrying about competition management when accessing objects in multiple threads, and Java's string is an example of an immutable object. Based on this, when you use Scala to create multithreaded applications, you can write unlocked code with the invariant state (immutable states) to write concise multithreaded code without worry
introduction of VaR and the generation of side effects.
Remove VaR and only introduce the necessary Val.
Instead of providing the required information to the caller of the method.
A notable feature of functional programming is that there are many methods, but method functions are very specific.
Here is an example:
Print a multiplication table from 1 to 10. The Java method is a dual for loop.
Scala is also
Mainly from the Coursera course "functional programming Principles in Scala"by Professor Martin Odersky, the inventor of the Scala language.
3. Data and Abstraction3.1 Class hierarchiesThis set of subtitles is out -,- of sync, listening to a little effort!The concept of a class is similar to that of other languages, such as base class, subclass, and p
Since it is functional programming, it is naturally unavoidable to know more about the function:Methods are not equal to functions (function)The method is not a function but can be converted into a function, can be converted by hand or automatically converted by the compiler (compiler) in appropriate cases. A reverse conversion is not a function that cannot be converted to a method. Let's take a look at the following example:1
Scala Programming implicit conversion and implicit parameter introduction
Scala offers an implicit conversion and implicit parameter functionality that is very feature-specific. is a feature that is not in programming languages such as Java. It allows you to manually specify that an object of some type be converted to
was successful. This is followed by some basic grammar learning in Scala. val Variable declaration: declares a Val variable to hold the expression's computed result, which is immutable.Val result = 1 + 1
Subsequent constants are available for continuation, Eg:2 * result
However, the Val constant declaration does not change its value, otherwise it returns an error.
var variable declaration: DECLARE var variable, can change the refere
)
Scala defaults to a direct delimiter for the behavior Code,
X
+ y
will be considered as two lines of code, x and + Y. But what if the same line of code needs to be wrapped. You can enclose the same sentence with parentheses, and you can use line breaks in parentheses.
(x
+ y)
is actually the line-break form of x + Y. Iii. Single-instance objects
Although Scala is a functional
Introduction
OK. The time has passed for another week. The first week has a May Day holiday, so I feel that the time is more than enough. In the middle of this week, no holiday can only be digested by evening and weekend time. In fact, it is still a little nervous! Later, we found that the video of each course also had corresponding courseware (Slide) and subtitles (subtitles) that could be downloaded. In this way, the download of video learning and online learning is only inferior to the Exerci
independent of the data type. This nature is called the independence of the expression. In a large-scale development system, the expression of independence is very important. It allows you to change the implementation of a component without affecting the customer code9. Regular expressionsOne particularly useful application area of extractors is regular expressions.Like Java, Scala provides regular expressions through a library, but extractorsMake it
Today I studied Liaoliang's Scala learning lecture 70th, about Scala's interface programming, so let's take a preliminary look at the process of programming in Scala.Information from DT Big Data Dream Factory public account: Dt_sparkFollow the account to learn more about the Liaoliang Teacher's course contentTeacher Wang qq:1740415547No.: 18610086859First of all,
)), Binop ("+", Var ("x"), Number (1)))ValE2 = Binop ("+", Binop ("/", Var ("x"), Number (2)), Binop ("/", Number (1.5), Var ("x")))ValE3 = Binop ("/", E1, E2)defShow (e:expr) = println (F.format (E) +"\ n") for(e Final Print Effect:1 - * (x + 1)2 x 1.5- + ---2 x 1 - * (x + 1)2 ----------- x 1.5 - + --- 2 x reprint Please indicate the author Jason Ding and its provenanceGitcafe Blog Home page (http://jasonding1354.gitcafe.io/)GitHub Blog Hom
Demonstrates value functions, anonymous functions, closures ...Other specific applications, but also in the production of it.This is over. Other Sam,curry, higher-order functions, sets, generics, implicit classes: These, or find a special book to get a deeper understanding of ...C:\users\hengheng>scalawelcome to Scala version 2.11.6 (Java HotSpot (TM) 64-bit Server VM, Java 1.6.0_43). Type in expressions to
Today to the bookstore to see a book called "C # Internet of Things Programming fundamentals " books, interested in the internet of things I grabbed to see, the book is the project is the host computer development projects, simpler, if the Internet of things development is just this, it seems that I do IoT development is more than enough. I looked at this
Today I studied Liaoliang's Scala learning lecture 70th, about Scala's interface programming, so let's take a preliminary look at the process of programming in Scala.Information from DT Big Data Dream Factory public account: Dt_sparkFollow the account to learn more about the Liaoliang Teacher's course contentTeacher Wang qq:1740415547No.: 18610086859First of all,
Contents of this lesson:A thorough explanation of functional programming in 1:scalaScala functional programming in the 2:spark source code3: Cases and jobsFunctional Programming Begins:def fun1 (name:string) {println (name)}Assign a function name to a variable, then this variable is a function.Val Fun1_v = fun1_Visit Fun1_v ("
, whereas Scala contains a while loop. This is because sometimes the imperative language solution is more readable, especially for people with command-language programming backgroundsIn general, we recommend your challenge while loops in your code in theSame the challenge VARs. In fact, while loops and vars often go handIn hand. Because while loops don ' t result in a value, to do any kind ofdifference to y
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.