本文主要内容摘自《Programing in scala 2nd Edition》。
Functional programming is guided by two main ideas:
The first idea is that functions are first-class values.
In a functional language,
- pass functions as arguments to other functions
- return them as results from functions
- store them in variables
- define a function inside another function
- define functions without giving them a name
functions that are first-class values provide a convenient means for abstracting over operations and creating new control structures.
The second main idea of functional programming is that
the operations of a program should map input values to output values rather than change
data in place. In other words, methods should not have any side effects. They should communicate
with their environment only by taking arguments and returning results. a method without any side effects are called referentially transparent.
Functional languages encourage immutable data structures and referentially transparent methods.