Reduce - the Suisse army knife of the modern programmer

By Ricardo Miranda

You must be logged in to access this page

Elevator Pitch

Python reduce is a powerful higher-order function. Being comfortable with reduce lets programmers be prolific and understand most modern programing languages - it is a transferable skill. It is also very powerful for Spark programming and any other context where immutability is required.

Description

Reduce is an extremely powerful function. In my former office, before the pandemic, me and my colleagues used to play games trying to convert every algorithm into a reduce function; we almost always succeeded.

Reduce can be used instead of recursive functions. If you are operating over iterables, probably you can use reduce. I advise you to use reduce instead, and I will explain why.

I will start explaining what is a fold in category theory, and show the mechanics of folding a List. I will show real world reduce usage in my own programming.

Last but not the least, I will show the convenience of using reduce in PySpark, because Spark structures are immutable. Reduce is a function present in most modern languages, so it is learning that a programmer can transfer to other contexts. In the end I hope you will get as excited as I am with the power and versatility of reduce.

Notes

My Python shows my passion for functional programming. Python is the business language where I can express myself the better. It is hard to introduce Scala or Clojure, not to mention Haskell, in a company.

In my programming I use comprehensions and reduce everywhere. It makes my programs compacts, legible and predictable.

In this presentation I want to show my sense of wonder with this powerful and simple function, reduce.