Before jumping into the course, Kyle walks through the agenda. He begins with higher-level concepts like composition, immutability, and closures. Then the course moves into list-specific operations including the use of map(), filter(), and forEach().
- Let's talk about our topic today. What on earth is functional-light programming? Completely made up term that I came up with to try to describe, what I hope, is the slightly more approachable, almost remedial, look at this much bigger and much more complex notion of functional programming. Some of you may be very, very familiar with functional programming already and for those of you that are, or for those of you that feel like you've cut your teeth on functional programming, you were a lister back in the 70s or whatever, if that's you listening to the tape, I apologize that some of this may feel very remedial to you.
But I think we have a problem because I think functional programming is one of the most powerful sets of techniques that we have in programming but I think it has been presented in a way that is completely off-putting to most developers. And I think if you cornered somebody who has been steeped in the traditions and the academics around functional programming, if you really ask them to admit, they would say it was a pretty high barrier to entry. It's like a really, really powerful tool. It's like walking into a workshop and seeing a chainsaw with all kinds of fancy features on it and things like that and maybe it's like digital and it has an LCD display and you're like, "I don't have any clue how to do that, "I just got a piece of wood I need to cut "and I have no idea how to use this thing," it's a high learning curve.
So, the workshop today, my goal is to try to get at some of those fundamental principles without wrapping any of it in any of that, sort of, academic notational terminology, things like that. We're not going to talk about monads, we're not ... To be honest with you, I'm not even fully sure I understand what a monad is. I can kind of fumble around with some of those sorts of things because I've been to, I can't even tell you how many, talks that claim to be the talk that's going to teach functional programming and I do not claim that this talk is going to teach you functional programming.
This workshop is not going to teach you functional programming, but it is going to teach you the basis upon which functional programming can be built. From the observational perspective, rather than from the academic perspective. That's why I call it functional-light programming. These are like walking into a workshop and saying, "Well, I don't understand that crazy, complicated "chainsaw thing, but I just have a tiny little "piece of wood that I need to cut," okay, here's a little handsaw. Okay? It's much, much simpler. It's much more remedial.
It doesn't take a lot of learning. You can figure out how to do this. The principles of handsaw are the same principles upon which a chainsaw is built but obviously the chainsaw is much more complex because it's designed to handle much more complex problems. So, what we're doing here is a start. It's not all of functional programming. But it's a start towards understanding where we need to go if we do want to be better with our functional programming practices. This represents my journey to understanding functional programming, if I really have to boil it down.
These are the sorts of things that, without ever understanding any of the terminology, I gleaned some of these concepts from programming and from looking at other people's code and I'm just trying to simply lay some of that stuff out to help you gain a better understanding. So, let's quickly look at what we're going to talk through in the next several hours. First, we're going to talk about what pure functions are and even before that we have to understand, obviously, what a not pure function is. So, we're going to look at the notion of not pure versus pure functions. We're going to look at composition, already starting to sound like a slightly fancy word, like a slightly fancy terminology.
I promise I'm going to help you understand what that word is. I chose that words as opposed to a number of other words that would make no sense at all. The famous quote about monads is, like, "Oh, they're just a bifunctor "in the category of endofunctor," or some crazy thing like ... we're not going to use any of that stuff, okay? So, don't get too scared with the terminology. Immutability. The notion that we have something that doesn't change. We treat it immutable, we can even make it immutable. So, we're going to look at what immutability is just from a very basic sense. Closure.
Closure is probably the most important programming concept ever invented. I know that's a big claim to make because there's a whole bunch of great programming concepts that have been created and we use lots and lots of great tools in our programming. But I would say that closure is the most core, the most important, the first place that we really need to grasp. So, closure. We definitely want to take a look just briefly understanding what that means and how we use that. Some of you may have already seen other courses and other books that I've written on it and I go into that topic in much more detail.
We're not going to go into a lot of detail about it but just to present to you the way that we use closure from a functional programming perspective. Recursion is another one of those topics that has usefulness outside of functional programming that is also very heavily related to functional programming. We want to have a basic understanding of recursion. Recursion is one of those things, I know, that is very easy to kind of get scared of. I've talked with students, college students, recently, who have told me things like, "I just can't even possibly wrap my brain around recursion," and that's a shame, I'm saddened by that.
I'm saddened by this notion that we can't figure out some basic way of explaining. So, this is my attempt to help you kind of get your brain a little more wrapped in that direction. Then we're going to look at a set of things these are going to build on higher order, so, slightly higher order patterns on top of these basic fundamentals. But they really are kind of the main takeaway from our workshop today. So, we're going to look at taking a list of values and performing a set of transformations on them. For those of you that have heard of functional programming before, transformation is done with maps, so, we're going to look at transformation and then we'll look at the map.
Then we're going to look at exclusion. Excluding items from a list. Pairing down a list to a smaller set of items based upon some condition. That goes by the name filter. Then we're going to look at composing items from a list into either a smaller list or even down to a single value. Composing values together. Now, I don't mean composing lists together. We're not actually going to take a very close look at that, but that's pretty straight-forward as well because we can concatenate two lists together.
So, from a purely theoretical perspective functional programming, they turn their eyes, you know, turn their nose up at something like list iteration. So, I just want to show you the notion of list iteration so that we understand why it's the, you know, like when we watch Sesame Street as kids and they're like, one of these things just doesn't belong. List iteration is going to be that thing that just doesn't belong but we need to understand the other things before we understand why list iteration doesn't belong. So, that's our set of topics that we're going to go through there. Our several exercises that we'll spend some time on and we will take some breaks throughout our discussion.
This course was created by Frontend Masters. It was originally released on 03/08/2016. We're pleased to host this training in our library.
- Pure functions
- Manual composition
- Composition utility
- List operations