<Becoming functional> it is a thin booklet published by o'reilly in 2014 this year (151). On the fifth page, it introduces the basic concepts of functional programming. all the code examples in this book are JVM-based programming languages, such as Java, groovy, and Scala. in order to be able to explain all the knowledge points, the author has to switch between multiple languages. In fact, using Erlang, elixir, or even C # is not so tired (because C # has LINQ, lazy .....).
This book focuses on explaining basic concepts and changing the way of thinking. therefore, no matter which functional programming language you are using, you can read it. The most frequently asked questions from Erlang's friends at the beginning are: tail recursion, side effects, higher-order functions, anonymous functions, closures. Here is a rather complex explanation. as an entry-level booklet, this book is simple enough to be quickly completed. below is the Mind Map and Text Version I made when I read the book.
Text Version
Becoming functional
First-class functions
Can either accept another function as an argument or return a function.
Pure Functions
Are functions that have no side effects. Side effects are actions a function may perform that are not solely contained within the function itself.
Side effects
Recursion
Allows us to write smaller, more concise algorithms and to operate by looking only at the inputs to our functions.
Tail recursion
Immutable Variables
Immutable variables, once set, cannot be changed.
Nonstrict (lazy) Evaluation
Allow us to have variables that have not been computed yet.
Strict evaluations-assigning a variable as soon as it is defined-are what we are used
Nonstrict means that we can have a variable that does not get assigned (computed) until the first time it is referenced.
Statements
Are evaluable pieces of code that have a return value.
Each line of code shocould be considered a statement, meaning there are very few side effects within the application itself.
Pattern Matching
Allows us to better type-check and extract elements from an object, making for simpler and more concise statements with less need for variable definitions.
Extracting Value
First-class functions
Anonymous Functions
Closures
Closures are much like Lambdas, counter t they reference variables outside the scope of the function.
In the simplest explanation, the body references a variable that doesn't exist in either the body or the parameter list.
Lambda Functions
Lambda functions are unnamed functions that contain a parameter list, a body, and a return.
Higher-Order Functions
A function becomes "Higher Order" if it accepts or returns a function.
Pure Functions
Output depends on input
When we don't return the result of our execution but rather mutate another external (I. e., not contained within the function scope) object, we call this a side effect.
Pure functions are functions that have no side effects and always perform the same computation, resulting in the same output, given a set of inputs.
Really, you want to make a function pure whenever possible; it makes the function much more testable and improves understandability from a troubleshooting perspective.