Eric Normand Courses/B05 Functional Programming in Clojure

  • $75

B05 Functional Programming in Clojure

  • Closed

Contents

The first three functional tools

How to develop a functional mindset

I've been asked many times how to develop a functional mindset. It was hard to answer because it's difficult to know what kinds of mindsets people have. After pairing with several people who had this question, I realized that the real problem was that they didn't know some of the basic tools for doing functional programming. Learn these three tools — map, filter, and reduce — and you'll be well on your way to developing a functional mindset.

filter
reduce

Combinators

Master intermediate functional tools

Combinators are an important part of functional programming. They are functions — usually small — that combine their arguments into new functions. They are an important part of any Clojure programmer's toolkit.

However, they can be difficult to learn. They're very abstract. And when should you use them? Here's the thing: once you learn them, you'll want to use them all the time. They're totally worth it.

When you learn them, you'll have at your command a powerful set of higher-order functions. You'll write code that is smaller and more powerful.

But we'll do more than that. We'll go through how each is implemented (they're all very simple). By doing that, you'll better understand some of the more powerful and interesting ideas in Functional Programming.


identity
constantly
complement
partial
fnil
comp
juxt
apply

Recursion

Recursion doesn't have to be hard

I get a lot of questions about recursion. For a lot of us, it's not something we've ever been taught or had to learn. It can feel unfamiliar and difficult.

But in functional programming, recursion is used quite a lot. It's not that different from iteration, and sometimes can be much easier to write, once you learn to see what's going on. It may be a struggle at first, but trust me, it's worth learning. You'll have more confidence dealing with nested data structures and recursive data.

In this introduction, I'm going to show you:
  • how to write recursive functions, step-by-step
  • the basic concepts so you never get lost
  • the 2 types of recursion (non-tail-recursive and tail-recursive)
  • the 3 parts of all recursions
  • how recursion is like a for loop
Along the way, we'll implement several familiar functions in terms of recursion. We'll learn:
  • how to maintain a seq's laziness when writing recursive functions
  • how to avoid blowing the heap by using tail recursion
  • how to convert regular recursion into tail recursion

length
map
filter
The Two Types of Recursion
filter with tail recursion
map with tail recursion
length with tail recursion
How is Recursion like a for loop?
Recursion and laziness
loop-recur

Reduce

Learn the most powerful functional tool

Reduce is the most powerful functional tool available. Whenever I write a recursive function, I ask myself whether it couldn't be better using reduce instead.

It lets you build general-purpose recursive solutions without doing the recursion explicitly yourself. In this course, we implement reduce and other functions like map and filter using it. This course also goes over some practical things you can do with reduce.


Implementing reduce
Implementing map using reduce
Implementing filter with reduce
reduce-kv
reductions
Average using reduce
reduced

  • $75

B05 Functional Programming in Clojure

  • Closed