- Redux Quick Start Guide
- James Lee Tao Wei Suresh Kumar Mukhiya
- 172字
- 2021-07-02 12:40:29
Pure functions
The most common definition of a pure function is a function that does not have side effects. This is to say that the returned value of a pure function is not affected, influenced, or changed by anything other than its input parameters. Provided the same input, the pure function always generates the same output. An example is as follows:
const sum = (a, b) => a + b;
This is an example of a pure function. Assuming that you call the function sum(6,9), the result is always 15, irrespective of the number of times that you run the function. You can be confident, if you are calling a pure function with the same input, that you are always going to get the same output, which means that the output is predictable. An example of an impure function is the following square function. In addition to returning the square of the number, the function might be updating the number in a database:
function square(number) {
updateNumberInDB(number);
return number * number;
}
- Android Jetpack開發:原理解析與應用實戰
- Flink SQL與DataStream入門、進階與實戰
- Microsoft System Center Orchestrator 2012 R2 Essentials
- Spring Boot企業級項目開發實戰
- 量化金融R語言高級教程
- C語言程序設計教程
- Lighttpd源碼分析
- Babylon.js Essentials
- Spring Boot+Vue全棧開發實戰
- 從零開始學Android開發
- C++ System Programming Cookbook
- Visual Basic語言程序設計基礎(第3版)
- Python計算機視覺與深度學習實戰
- Visual FoxPro程序設計習題及實驗指導
- Managing Windows Servers with Chef