We do spark development using a lot of spark's higher-order functions so today I'm using scala higher-order functions on Linux Services
Declares a list collection:
The package containing the list is already automatically introduced by the predefined, so there is no need to introduce a package here, directly using the list instantiation object, actually using the list object object's Apply method
We use the map function to multiply each value in the list by 3:
x represents each element in L, and map iterates through each element in L, because there is only one type of element in the list, so we can omit its type when performing a horse-fart operation, as follows:
When there is only one parameter in the list collection, we can remove the parentheses in the argument:
To save all the code, I'm going to use idea.
Collections in Scala:
The collection mainly includes list, set, Tuple, map, etc.
Create a Scala class under the Org.scala.collection under Scala collectionoperations
Create a list instance in idea:
Let's take a look at the list code implementation:
The source code says that its internal is the way of apply to complete the instantiation:
Instantiate the set in the same way:
We can also look at the implementation of the set instantiation object:
Next we cut the set in the Linux command-line terminal, first look at set:
Duplicate elements are not stored in the discovery set
See below for the Declaration and use of the tuple:
When a tuple is accessed, the subscript is starting from 1.
For a tuple, if there are only two elements, we can create them in the following ways:
Now let's look at the definition of map:
The map itself uses a variable parameter, so you can assign multiple values to the map:
Let's take a look at the option type, option represents an optional value:
Option has two sub-classes: Some and none, and look at the use of option:
Next we look at the use of filter:
Zip operation on the collection:
Let's look at the partition of the collection:
Use Flatten's multi-collection for flattening operations:
Flatmap is a collection of map and flatten operations, with the map operation before the flatten operation:
Getting started with Scala -09 Scala high-order functions