Functional Python Programming
Higher-order Functions We'd like to be able to express f(sel2(s_e_d)) for s_e_d in trip. This involves functional composition; w ...
Chapter 5 We can revise this slightly to create a higher-order function that separates the wrapping from the other functions. We ...
Higher-order Functions Flattening data while mapping In Chapter 4, Working with Collections, we looked at algorithms that flatte ...
Chapter 5 def numbers_from_rows(conversion, text): return (conversion(v) for line in text.splitlines() for v in line.split()) Th ...
Higher-order Functions This will try to assemble a tuple of n items taken from an iterable. If there are any items in the tuple, ...
Chapter 5 Using Python for functional programming means walking on a knife edge between purely functional programming and impera ...
Higher-order Functions We can define a function as follows: def first(predicate, collection): for x in collection: if predicate( ...
Chapter 5 This function steps through the items in the iterable. It attempts to apply the function to the item; if no exception ...
Higher-order Functions The call() method is how the resulting function is evaluated. In this case, the function that was created ...
Chapter 5 The benefit of using a Callable to create a composite function gives us slightly simpler syntax when the resulting com ...
Higher-order Functions Generally, this count_not_none() object will behave like any other Python function. The use is somewhat s ...
Chapter 5 We've looked at several kinds of higher-order functions that work with a collection of values. Throughout the previous ...
Higher-order Functions Summary In this chapter, we have seen two reductions that are higher-order functions: max() and min(). We ...
Recursions and Reductions In previous chapters, we've looked at several related kinds of processing designs; some of them are as ...
Recursions and Reductions Simple numerical recursions We can consider all numeric operations to be defined by recursions. For mo ...
Chapter 6 Without these constraints. a-1 can't be guaranteed to approach the nonrecursive case of a == 0. In most cases, this is ...
Recursions and Reductions Stepping outside purely functional processing, we can define an imperative facti() calculation as foll ...
Chapter 6 This function has three cases. The base case, the fastexp(a, 0) method is defined as having a value of 1. The other tw ...
Recursions and Reductions Following is an alternative which restates the entire algorithm to use stateful variables instead of a ...
Chapter 6 Following is a purely recursive function version of the older map() function: def mapr(f, collection): if len(collecti ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf