Transcript
English (Auto-generated)
Hello everybody. I have done the 8th lesson now and I did the pattern matching with guard lessons. So we are going to work on the homework that he has signed in that lesson. So he wants us to implement a module with all functions that have the exact same name that have specific things they returned based off of what they received. So I've gone ahead and copied over the actual tests that are essentially here and out of the I. O. Inspect. So we can just run them on our console. So now we're gonna start building out our actual module. So we'll do our depth module and we'll call it my module to match the test down there and then we'll do that too. Do that. My function. Um I just realized something else I did is from here When I was setting it up. I did this but I should have been recording when I did this I took and I changed them in order of of argument number so I've listed so this is what gets one argument one argument one argument 2-2 and three. Oh this is one. I have to ah So this needs to go up That's one argument. So we have 1111223. Perfect. So what we're gonna do is we're going to start with this first one here which is gonna be a string. So we're gonna say when my function we're going to take a string and we're gonna say when is binary. Perfect you and we're going to say hello and then we're going to contaminate the string inside of it. There will be all we need for that one. So we'll test that that works here. Yeah. Perfect. Um awesome. So let's undo the next test. So this one is going to be for lists. I don't think we need to list. Anyways returns to some of our list of elements that are sized to our last elements. Some of the elements returns to. So we want we're testing the length I believe some for list elements. Yeah so the length I think that's my understanding of what that is. It's a little confusing. Um not string. We're gonna have a list and we're gonna say when is list and we're gonna test that's a list and then we need to do and um there isn't available um parameter where you can test the length of lists just like this. So we're gonna do an length list is less than or equal to two you and we're gonna return the length of the list. So now it's from that To get rid of one of those there it should be returning one. Perfect and if we add too many we should get an error. Perfect. Both of those are working. So let's take the next test returns 24 product of list elements for sizes three or more. Okay so we want to specify that the function is going to be taking a list again but this time the list is going to have a list of three or greater. So let's actually just copy this here And we're just going to switch this around and say greater than 33 or greater and perfect. Um Product of list elements for sizes three or more. So we have so we want to 22 times three is six times 4, 24. Yes, we wanted times all these together. Um I can't do recursive because once the function gets less than three items, it's gonna call it different functions so that won't work properly. So, let's see what we have available in our functions. Mm hmm. First of all flats produces a given lift from left to right from the left with the function requires an accumulator. The peculiar function. Okay. We should be able to use this. Okay. So it is for you to access list before old pal. And then we will do list. Accumulator is just gonna be one. Um and then we need to write the function which will be How is this? I've never done this before. Okay. The X accumulator. X. And what we're doing. Okay. So we're gonna say x. And our accumulator. And then we will do accumulator times. Mhm. Thanks. Next time the accumulator. But I don't think it makes a difference. Ship. It won't make a difference, but it's gonna bother me. So this should take each staying here and go over it by times in it. So we should have one and then folds. The car is an accumulator. So this is doing let's see here, I'm pretty sure that's right. Oh, it is A very clear message. 24. Perfect. So yeah, it's going over and then if I was to increase the accumulator to to it it should be 48. Okay, Okay, so my understanding is that how that works is correct. So it is taking each element of the list and the accumulator and it's time sing it and then reducing it down. So that's a little confusing. I wish this described it better because these are really weird. Oh, because it's going to be taking I know list. So it takes the first element is going to say one She later is 1. 1 times one is 1. Okay then it's going to take and I was going from left to right All the accumulators one. No, it's safe to say I don't understand how this works. Elixir 1, 2 3, 4. I outputs. Yeah, let's do that. Let's do an IO puts here. So we understand io dot puts What are you taking expression two times what Let's try and I don't expect to see what happens. 1, 2, 6, 24. So it's taking one times one is 11 times two is two, two times 3, six. Three times four. No, I don't get it just iterated from start. The fun times the following order. Oh, it's taken by the result. So it's doing one Times one is 1, two times 1 is two, three times 2 is six, six times two or four times six is 24. I understand. Okay, that was a process. Sorry for that whilst watching my framework. Okay, moving on to the last one of one function which we're going to be looking for a tuple to death. My function When is tuple people assume a tuple with size of two. Okay, so we're not checking it for size of two. Okay, so we're gonna actually change this so two, keep one to he's just saying assumed so I don't think he wants us to actually check for it um and then we're going to say mhm saying hello Apple and jen but I, I don't think that's what he wants it to say. I'm going to assume this is supposed to say hello john and jenn not hello Apple and jen, I'm going to just thanks Yeah because we're not using this here. Yeah, I'm just gonna say to one and coupe two, I'm going to assume that the typo mhm Hello john let's get rid of this. Hello john and jenn Perfect. Alright, so next one is my module to return 31 plus two. Okay deaf. My function. Um Someone want to len is number ah And his number. num one and okay this number, I don't know if there's a faster way to do that. I don't think so. I think we need to check all the different let's see here. Mhm. Okay. Um Mhm. Guards. Okay. one is last is function is number. Yeah it's gonna have to do it one at a time. Okay that's fine. Number is number we're gonna do num one plus um to it didn't tell us a check for anything. It's just saying it wants to take two numbers and so I'm just gonna run out like that. We have three turns 3. We could add checks on to make sure that it had a Like it was two digits but it's I'm just gonna do it that way. Okay so for this one we're taking two strings. So we'll do deaf. My function. one string to when his binary strike one and his binary string pill. Do you string one? I do space and I'm just gonna get this string too sure. Why did you do that? That was great. So we're doing javascript. Hello world. Alright. And last one. Return six. So we're going to do this but we're gonna add one more three. I don't know if there's a better way to do this because they're individual arguments. I feel like this is not something we would do in normal situations. So I'm interested to see if he goes over tomorrow if there's a better way to do this and his number. Number three plus number three. Yeah. Perfect. So then we could do what we did before where we could do deaf. My function parks broken. But if we did like this coffee is down like this and we'll add another Bridget here glass when we should get is broken to function four. Oh, that's only for one. Okay. I'm just gonna leave it. We don't need he didn't ask us for checks and that's fine. But we got all those to work via specific guards so hopefully that is the best way to do it. Um This is very expensive but it's what we're working with.