DEV Community

Cover image for Let's chat about functional programming...
Roy R.
Roy R.

Posted on • Edited on

Let's chat about functional programming...

Let's talk about functional programming, map/reduce/filter and a little bit of a hack to using it's benefits that forms part of it's appeal.

Software Engineers often want to expand their repertoire into learning new languages. When they do, it takes time, there is often a learning curve, the core libraries may take years to become familiar with, and even getting to a point of basic competence absorbs a lot of time.

Map/Reduce/Filter are a powerful set of tools within a functional approach that can be used in a lot of languages. Indeed, there are some languages where map-reduce(and filter too I suppose) are the main tools that you are expected to use to manipulate data.

So can we actually use map/reduce/filter as a way to get started quickly in a new programming language?

Maybe.

  • [ ] If the language supports clean map/reduce/filter at all.
  • [ ] If the map/reduce/filter paradigm of the language is clean enough to simply memorize. I have run across some Inconsistent APIs for map/reduce/filter that make it harder.
  • [x] Then maybe you can get to a workable level of effectiveness with map/reduce/filter way, and learn the rest of the language more gradually.

Have you tried getting started with just these parts of a language first?

Top comments (3)

Collapse
 
totally_chase profile image
Phantz

Many, if not all, functional language tutorials/guides rely on map/filter/reduce to build the reader's foundation. Usually, a good place to start for learning new languages is to solve some project euler problems. Once that's done with, one can move on to more practical shenanigans.

So functional languages more or less force a new user to get started using those parts of the language. And it works, like....really damn well! Especially folds (i.e reduce), folds can do absolutely everything. After you have a neat understanding of higher order functions, you start to realize that map/reduce/filter can do practically everything. They're foundational parts of control flow as well as data manipulation.

Eventually one might find themselves getting all philosophical and wondering why does it work so well. They, then, might consider looking into the abstract idea behind these concepts, at which point they might stumble upon functors (mapping), monads/selective functors/profunctor choice/arrow choice (filtering), and foldables (reduce, formally known as "fold"). From there, they might start developing their intuition further between these abstract concepts and stumble upon monoids. And how almost every concept in programming somehow magically describes......a monoid. Odd, but cool! Then endomorphisms, and then.....satisfaction, for a while.

Yes, I've been through that journey, starting off functional programming with those basic tools, realizing how weirdly strong and universal they are, and eventually realizing why they are so universal. It's fun, would recommend.

Collapse
 
rrsai profile image
Roy R.

Yeah, certain languages I think lend themselves better to getting more depth into the abstract concepts that assist with functional programming. I'm curious what language you're generally coming from? as I haven't had to deal with monoids or even come across the term before, had to look it up here:
betterprogramming.pub/functional-p...

Collapse
 
totally_chase profile image
Phantz

Haskell ;)