This is just crazy moon poetry and you just have to deal with the fact that it’s there and most of the time you just figure what line number it is and go looking at them Okay What is the problem? The problem is, all our other functions sort and reverse took a list of lines and did something to them but we wrote something which takes a string Okay So, we’re going to use something called map Map to the rescue now, you probably all at this day and age program did a language that has a collections library and that collections library has either a four each or a map function, right? And usually map takes a functional argument, a function pointer or it depends on the language your working in and iterates through the collection applying the function and gathering up all the results and returning you a new collection This is nothing new Map exist and you–I’m certain everyone here has been exposed to a map function and just to make sure we are to realize what we’re talking about I gave you some examples, compare if we map reverse over this list of strings, right, it reverses each individual string versus mapping reverse to the list of strings which map reverses the list itself, got it? All right The same thing is like sorting some of you might at this point be scratching your nose and go, Wait, does reverse work on a list of strings or does reverse work on a string? The answer to that question is, yes it does both Okay So, to indent each line of our poem, right? I have to do something by lines but I better map, all right, by lines expects a function over a list So, I’m going to map indent over that list By lines map indent I could also factor that whole pattern out because we had a thing called by lines, have it each line, given a function–now, I’ve written this–now I’ve written a type Given a function from a string to a string, notice the parenthesis and the string return a new string So, let’s–let’s look at what’s going to happen, each line F is going to take this–it’s going to take a string, apply lines to it, give us a list of lines, map our function F over each individual line and then unlines the result back together into one big string to return So, each line is now useful utility function which does something–apply something to each individual line Yes? >> When you write maps space indent is that the same as indent.map? >> LENTCZNER: No, it is not So, the question was when you write maps space indent is that the same as indent.map? No, it is not We are passing indent as a function, as an argument to map >> Okay Map is a function >> LENTCZNER: Map is a function, right There’s no period or object There’s no receiver in this language It is not object oriented So, map is just a pure function at the top there but we’re going to–you’re getting close to a problem Anyway, close to [INDISTINCT] so indent line, we can do it this way or we can use this combinator of this thing we just build called each line–each line indent and then if you run them either you get indeed an indented poem, it’s very exciting But wait, where is the second argument to map? I told you back here, map takes a function and a list and returns a list In fact, at this point, looking at that top line should hopefully be kind of clear that that’s what that says It takes, right? It starts with it takes a function from A to B, a list of As and gives you a list of Bs but in this code up here, there is no second argument to map Where is it? All right Because it’s not there Because map of F–so look at map this way, we can say map takes a function from A to B and because [INDISTINCT] just trust me I can parenthesize the remainder So you can think of map as taking a function from A to B and turning it into a function from list of A to list of B, got that? If I just applied map to the first argument, I get back a new function it’s called [INDISTINCT] it’s [INDISTINCT] and I get back a new function, a function list of A to B, it turns, our indent which only works on a string to a version of indent which works on a list of strings We call this lifting or lifting up, map is kind of bringing our simple function up into the world of lists and that’s what’s going on All right And we’ll write some more code here, quickly I want to yell because we like yelling, right? So, this is another function from string to string and so, I’m going to yell and I’m going to map this function called to operate from the library listed uppercases characters And I map that over the string and I append a bunch of exclamations, and I’m going to