Functional Python Programming
The Functools Module Since Python Numbers class is intended to be immutable, ordinary functional design can be applied to all of ...
Chapter 10 Applying partial arguments with partial() The partial() function leads to something called partial application. A par ...
The Functools Module Reducing sets of data with reduce() The sum(), len(), max(), and min() functions are—in a way— all speciali ...
Chapter 10 max= lambda iterable: reduce(lambda x, y: x if x > y else y, iterable) The sum2() reduction function is the sum of ...
The Functools Module We've used the operator.add method to sum our values instead of the longer lambda form. Following is how we ...
Chapter 10 Using map() and reduce() to sanitize raw data When doing data cleansing, we'll often introduce filters of various deg ...
The Functools Module If we use the clean_sum(comma_fix_squared, d) method as part of computing a standard deviation, we'll do th ...
Chapter 10 Following is the same feature done with the itertools.groupby() function: def partition_s(iterable, key= lambda x:x): ...
The Functools Module Both will provide us summary values for each group. The resulting group statistics look as follows: 1 5.34 ...
Decorator Design Techniques Python offers us many ways to create higher-order functions. In Chapter 5, Higher-order Functions, w ...
Decorator Design Techniques As an explicit operation that returns a new function, possibly with a new name: def original_functi ...
Chapter 11 We almost always want to use the functools.wraps() function to assure that the decorated function retains the attribu ...
Decorator Design Techniques We could also create the null-aware rounding function using the following: nround4= nullable(lambda ...
Chapter 11 Because we can't easily fold in new attributes, it's difficult to locate reasons to modify or extend the way the wrap ...
Decorator Design Techniques Composite design The common mathematical notation for a composite function looks as follows: fgxfgx ...
Chapter 11 A great deal of functional programming amounts to fgx()() kinds of constructs. We often spell these functions out bec ...
Decorator Design Techniques This function wraps a given conversion function to try a second conversion in the event the first co ...
Chapter 11 In Python syntax, we can write it as follows: @deco(arg) def func( ): something This will provide a parameterized dec ...
Decorator Design Techniques A parameterized decorator has three parts and they are as follows: The overall decorator. This defi ...
Chapter 11 Implementing more complex descriptors We can easily write the following commands: @f_wrap @g_wrap def h(x): something ...
«
7
8
9
10
11
12
13
14
15
16
»
Free download pdf