官术网_书友最值得收藏!

Introducing Essential Functional Concepts

Most of the features of functional programming are already first-class parts of Python. Our goal in writing functional Python is to shift our focus away from imperative (procedural or object-oriented) techniques to as much of an extent as possible.

We'll look at each of the following functional programming topics:

  • First-class and higher-order functions, which are sometimes known as pure functions.
  • Immutable data.
  • Strict and non-strict evaluation. We can also call this eager versus lazy evaluation.
  • Recursion instead of an explicit loop state.
  • Functional type systems.

This should reiterate some concepts from the first chapter: firstly, that purely functional programming avoids the complexities of an explicit state maintained through variable assignments; secondly, that Python is not a purely functional language.

This book doesn't attempt to offer a rigorous definition of what functional programming is: Python is not a purely functional language, and a strict definition isn't helpful. Instead, we'll identify some common features that are indisputably important in functional programming. We'll steer clear of the blurry edges, and focus on the obviously functional features.

In this chapter, we'll include some of the Python 3 type hints in the examples. Type hints can help you visualize the essential purpose behind a function definition. Type hints are analyzed with the mypy tool. As with unit testing and static analysis with pylint, mypy can be part of a toolchain used to produce high-quality software.

主站蜘蛛池模板: 梁平县| 鹤山市| 金山区| 南宫市| 榆中县| 丹寨县| 论坛| 泽普县| 赫章县| 新田县| 慈利县| 阳谷县| 赤峰市| 莫力| 西昌市| 繁昌县| 鄂托克前旗| 营口市| 夏河县| 巴林右旗| 卢湾区| 任丘市| 沧州市| 兴国县| 南投市| 呼和浩特市| 桦川县| 益阳市| 宁夏| 增城市| 五峰| 建平县| 栾川县| 新乡市| 新竹市| 汝阳县| 安溪县| 铜陵市| 齐河县| 淮北市| 连南|