Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Functional Python Programming
  • Toc
  • feedback
Functional Python Programming

Functional Python Programming

By : Steven F. Lott
4 (9)
close
Functional Python Programming

Functional Python Programming

4 (9)
By: Steven F. Lott

Overview of this book

This book is for developers who want to use Python to write programs that lean heavily on functional programming design patterns. You should be comfortable with Python programming, but no knowledge of functional programming paradigms is needed.
Table of Contents (18 chapters)
close
17
Index

Composite design


The common mathematical notation for a composite function looks as follows:

The idea is that we can define a new function, , that combines two other functions, and .

Python's multiple-line definition of the form is as follows:

@f
def g(x):
    something

This is vaguely equivalent to . The equivalence isn't very precise because the @f decorator isn't the same as the mathematical abstraction of composing and . For the purposes of discussing function composition, we'll ignore the implementation disconnect between the abstraction of and the @f decorator.

Because decorators wrap another function, Python offers a slightly more generalized composition. We can think of Python design as follows:

A decorator applied to some application function, , will include a wrapper function. One portion of the wrapper, , applies before the wrapped function and the other portion, , applies after the wrapped function.

The Wrapper() function often looks as follows:

@wraps(argument_function)
def something_wrapper...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete