DEV Community


Discussion on: Introduction to functional programming with Python examples

daveparr profile image
Dave Parr

Really good article. I come from an R background, where map, apply, reduce is very common in a number of forms.

Something I want to pick out to ensure I've understood the python variant:

In functional programming, functions are the first-class objects, also called higher-order functions — the data types treated the same way as other types.

I think this sentence might be able to be refined, or my understanding might be wrong.

First class functions are a feature of the language where functions can be passed as arguments/data structures.

Higher order functions are a subset of functions (like map as you identify later), but not all first class functions are higher order functions, as a higher order function modifies the behaviour of a function that is it's argument.

So while 'print' is a first class finction, e.g. it can be given as an argument, 'map' is a higher order function, as you can map a print over a list. Conversely you can't 'print' a 'map' over a list.

Am I understanding this correctly or is this not true in python?