Functional Python Programming
Introducing Some Functional Features First-class functions Functional programming is often succinct and expressive. One way to a ...
Chapter 2 There isn't a trivial way to guarantee a Python function is free from side effects. It is easy to carelessly break the ...
Introducing Some Functional Features Since the max() function is a higher-order function, we can provide another function as an ...
Chapter 2 For example, look at the following command snippet: max(map(lambda yc: (yc[1],yc), year_cheese)) (33.5, (2007, 3 ...
Introducing Some Functional Features In Python, the logical expression operators and, or, and if-then-else are all non-strict. W ...
Chapter 2 We can use this noisy numbers() function in a way that will show lazy evaluation. We'll write a function that evaluate ...
Introducing Some Functional Features We'll look at a simple iteration to test a number for being prime. A prime number is a natu ...
Chapter 2 ()[ ) () ()[ ) True coprime , , mod 0 coprime , 1, ab nab na na b ab = = ≠∧ + < if if This version is relati ...
Introducing Some Functional Features The non-strict and operation is implemented by splitting it out into a separate if statemen ...
Chapter 2 Here is TCO done as a generator expression: def isprime(p): if p < 2: return False if p == 2: return True if p % 2 ...
Introducing Some Functional Features Familiar territory One of the ideas that emerge from the previous list of topics is that mo ...
Chapter 2 The topics are as follows: Referential transparency: When looking at lazy evaluation and the various kinds of optimiz ...
Introducing Some Functional Features Although many functional languages have sophisticated type systems, we'll rely on Python's ...
Functions, Iterators, and Generators The core of functional programming is the use of pure functions to map values from the inpu ...
Functions, Iterators, and Generators We'll write generator expressions that will perform the following tasks: Conversions Restr ...
Chapter 3 We can't easily eliminate all stateful Python objects, except from small programs. Therefore, we must manage state whi ...
Functions, Iterators, and Generators We can assign functions to variables, pass functions as arguments, and return functions as ...
Chapter 3 We can create instances of our Mersenne1 class with an embedded strategy algorithm, as follows: m1s= Mersenne1(shifty) ...
Functions, Iterators, and Generators To make this more consistent, we can consider defining our own prefix functions for the str ...
Chapter 3 We'll almost always use tuples (and namedtuples) in the context of a collection of values. If we're working with singl ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf