Placeholder Image

Subtitles section Play video

  • What's going on, guys, welcome to a medical school.

  • My name is Nelson.

  • And in this course, I'm gonna teach you everything you need to know about functional programming with job.

  • So when I first saw functional programming, I was like, you know, what is this?

  • I saw functions by function, credit cards being used all over the place.

  • And to be honest, I only realized the power of it when I learned about the clarity programming.

  • So you see, most of us write imperative programming, which means that you define every single implementation detail off your code.

  • Whereas the clarity simply tell it what you want instead of defining.

  • You know the details, for example, you might have a variable.

  • Or actually, you might have a loop.

  • Right?

  • So you define, you know, the initial value howto increment it and how to stop it.

  • Right?

  • So with the clarity of programming, you have none of that.

  • You simply tell you what you want.

  • And that's why I'm gonna teach you in this course.

  • So in this course I'm a teacher.

  • Exactly.

  • You know what the difference is?

  • What?

  • The differences are between imperative and clarity, programming and why you want to move away from imperative programming.

  • Then I'm gonna teach you about the functional interface is that Java has to provide so functions by functions predicated consumer suppliers and all that good stuff, right?

  • So once you learned that, you can then start to use streams and optionals to write code in a clarity of way.

  • And then towards the end, I'm gonna teach you one of my favorite design patterns when it comes to functional programming.

  • And that is the Combinator design pattern, which is really, really awesome.

  • It's really good for validation where simply defined all over your validations in the interface.

  • And then you define exactly step by step what you want your validation to be.

  • It's really, really awesome.

  • And finally, I'm also gonna teach you exactly about Lambda is callbacks and the property's off functional programming so that you fully grasp exactly the whole concept.

  • So if you haven't subsided my YouTube channel, go ahead and subscribe, because that way I can provide more awesome content like this without further ado.

  • Let's go here, then everything you need to know about functional programming with Java.

  • All right, so before you start this course, I wanna make sure that you really learned from this course because I wanna add value.

  • So what I want from you is to go ahead and practice as I teach, because that's the best way for you to learn any new technology.

  • Also, go ahead and join the private Facebook group.

  • So if you have any questions, go ahead and engage with the students.

  • And the group is full of cool people just like you.

  • So this is all I wanted to say for now.

  • And enough of me talking.

  • Let's go ahead and land about functional programming.

  • All right, let's go ahead and both drop our application where I'm gonna show you all the examples throughout this course.

  • So I've got intelligent right here.

  • And if you've never used intelligent, then I highly suggest you to enroll.

  • Tow my free course where I teach you permit how to use this Awesome I d.

  • E.

  • And to be honest, as a software engineer, this is probably the idee over your choice when it comes to Java back and development.

  • So let me go back to intelligence, and the first thing I'm gonna do is to create project and right here I'm going to pick Maven now.

  • The project s decayed.

  • It doesn't really matter whether you use Java 11 12 or any other version as on this is above 1.7.

  • So I'm gonna stick Weighed 11 right here.

  • And as I said, the version does not matter.

  • Next.

  • Let me go ahead and click next and then right here for the group I d.

  • I'm gonna say calm, don't and then and me goes and in code.

  • So right here.

  • This could be your own organization.

  • And right here, let me simply name this as Java and then funk, you know, an animal press next.

  • And then I'm gonna save this on the code and then java functional, and then simply press finish.

  • There we go.

  • Let me actually collapse this maven tab right here and also limit collapse this and right here, go ahead of simply enable or import to import dependencies.

  • And this is the actual palm foul, right?

  • So if I open the functional Oh, actually, Java functional folder inside, You see that we have on Lee Deep Palm foul and this contains the group I d alter fact I d and then the actual version.

  • So let me just move that line and also removed this pop up.

  • And finally, I'm gonna put this full screen, and this is all on.

  • Actually, let me just close this because we're not gonna need this poem foul.

  • And this is pretty much everything you need in order to both trapped the application to follow along.

  • So obviously, I'm gonna give you the source code at the end off this course, But I highly suggest it to practice as I teach, because that's the best way.

  • Aww.

  • You learning any new topic?

  • This is often Now if you have any questions about intelligent.

  • As I said, go ahead and roll to my course right here where I teach you everything you should be aware off this awesome i d.

  • Let me go ahead and give you an example off Imperative programming.

  • So imperative programming involves you as a developer.

  • The finding every single detail about your implementation.

  • So right here inside offthe e source folder inside, off main and in Java.

  • Let's go ahead and create new package so you can right click on this folder or, um, I used keyboard shortcuts and also you can see down here.

  • So right here.

  • You can see all the keyboard shortcuts that I'm gonna use throughout this course.

  • So right here, I'm gonna use on the er someone select package.

  • And then right here, my name decides Impair that if and then Okay, now inside.

  • Go ahead and create Kloss and this will be called as Maine.

  • Now, let me collapse this and inside I'm gonna type P s and then V m for public static.

  • Maine.

  • There we go.

  • And now we have a main effort that we can run.

  • So let's go ahead and define a list.

  • And the time off this list will be off type and in person.

  • So right here, let me go and complete name decides people equals two and enlist and then dot and then off.

  • So right here we're gonna do a simply create feel.

  • People were actually a few people off time person.

  • So right here, let's go ahead and simply create a class.

  • So let's go intimacy, static and in class.

  • And then person and this person will have a name so private and then final string and in name.

  • And we also will define a gender.

  • So Denham and this will be engender.

  • And the gender will be male or female.

  • And then right here, what we're gonna do Oh, actually underneath basically say private final and then gender.

  • And that will be the gender.

  • And let me ideas took were struck there and there we go.

  • So now we have this class right here called person, and let me also define into extreme effort right here, so two and a string.

  • And there you go.

  • So now, right here, we can simply say list off and then new and then a person.

  • And right here, let's give it a name.

  • So John and John is a male.

  • And let me have they started in port for this.

  • And let's go ahead and duplicate this.

  • So I'm gonna press Come on d A couple of times.

  • And Eric Oh, so let's have a Maria.

  • And she's a female list of pay.

  • Isha, she's also a female.

  • Just like that.

  • This have Alex the male, and this finally have Alice just like that.

  • And Alice, She's off course a female.

  • So now that we have this less right here, let's go ahead and find out how many females that we have.

  • So the way that we will do it with Ah, the imperative approach is let me have a common right here.

  • So in an imperative approach is simply by doing the falling.

  • So first we need an empty list and then off time and in person.

  • And then let me simply say females right here equals to list off.

  • And then I actually know even least off Vesco Agency knew in an array list.

  • So this is empty list.

  • Now.

  • What we need to do is to loop through people.

  • So let's go ahead and you'll be safe.

  • Four and in person and in person, inside off people.

  • And right here we're going to say, if an in person actually let me go innocent was, say female and then dot equals two person dot and engender just like that.

  • So if this is the case, I'm going to say females don't and an ad and then a person just like that, and that would send my column and then right here at the very end.

  • What I'm gonna do it simply print each people.

  • So again, let me simply copy this just like that.

  • And then right here this instead.

  • Off people, this will be females, females, and this will also be female and then south, just like died.

  • So system got out the print line Hopes just like that.

  • And then female.

  • Now if I go ahead and pretty much run this class right here, So let's go ahead and run this class can and there we go.

  • So right here you can see that we have on Lee females in our output.

  • And basically, this is pretty much what imperative programming.

  • It's so basically we're defining every single detail.

  • So right here you can see that first we have an entire list and then we loop through that and then we have an IV statement and finally we have a final four loop looping through females and you can see that there was a lot of logic not, you know, you know, a substantial amount of logic.

  • But see that, for example, this if statement is some logic and also you can see that this is a lot of code for something very simple.

  • And this is what I wanted to show you about the imperative approach.

  • Next, let's go ahead and implement this using the D clarity of approach and you will see that it's much neater.

  • And we put much just tell it what we want to do instead of defining every single implementation detail right here.

  • So to use declarative approach with Java, a functional style programming, we simply have to do the falling.

  • Let me collapse this So right here.

  • So what going to do here is instead of us creating a list and then having to fold up So what I'm gonna do is the following first, let me go ahead and premature.

  • Have a comment, and right here this will be declare authorities in an approach.

  • Now, the way that we used the clarity of approach is by using streams, we'd collections.

  • So don't about, um so much about what stream is because I'm gonna show you exactly they're on.

  • But for now, just follow along.

  • So call ahead and simply say people.

  • So people is the original list right here.

  • So this list off people and then dot and then stream right here.

  • So now we have a stream and a stream allows us to go into an abstract mode where was simply telling what we want.

  • So right here.

  • Let's go ahead and simply say dot and then filter.

  • And what we want to filter is basically this.

  • So right here we have a person.

  • So this takes a person, and I want to say the exact same thing right here.

  • So I'm gonna take this eighth statement lips.

  • Let me press command w a couple of times come and see and then put it here.

  • Very cool.

  • So you see that I'm filtering and then this takes a person that I'm using This the same if statements, basically female dog equals and then personal gender, right?

  • And finally, I'm going to say don't and then collect and then collectors and into list and the week semi column.

  • And right here, what I'm gonna do is put this on a new line in the same we'd collect just like that.

  • And right here, we conceivably now go ahead and simply say dot and then for each and then we can use system dot and then out and then column, column and then print line.

  • So now let me actually add, um, right here.

  • So let me simply add this as a south.

  • So I'm gonna print this just like that.

  • There we go.

  • And let me do the same here.

  • Someone copy that.

  • And in priest that Take this comment, put it here so you can see exactly in the council what I'm doing.

  • So now you can see that this is much concise and right here you can see that I'm not creating a list and adding to that list and then doing the if statement so on and so forth, you could see that is very straightforward.

  • And I'm just telling you what I want.

  • So from the people array list or a list, basically, this is a list I'm gonna stream.

  • So I'm gonna go into this abstract mode, Then I'm going to filter all the females, and then I'm gonna collect to a list.

  • And finally, I'm gonna print everything.

  • So technically, I don't even need this collector list because I'm simply printing our things.

  • So let me simply run this for now.

  • Secrecy exactly was happening.

  • There you go.

  • Basically, you could see that we have the exact same output.

  • Right?

  • So if I put this whole screen, you can see that we have the exact same output.

  • But the D clarity approach is much Nita.

  • So obviously, if you were to have this into a less right here, So this is where collect comes into play and then I can remove this line and this with semi column and an extra interest to a variable and then say females and then to write.

  • And you can see that Now I've got a list right here, and I could again simply say females tue dot and then for rich system, don't out calling column print line.

  • So if I run again, you can see that this is the exact same output.

  • So there we go now.

  • You should have a full understanding off the differences between the Clarity's and imperative approach.

  • So obviously, I've just shown you, you know, the difference between both.

  • But there are few things that we need to understand in order to write code like this, right?

  • Someone teach you about functions by functions, pretty goods by predators, consumers, and you know all the good stuff that Java has to offer when it comes to functional programming.

  • If you have any questions, go ahead and Germany message otherwise, let's move on.

  • All right, let's go ahead in the section learn about the Java thought you till that function package.

  • So basically, this package contains functional interface is that provides target times for lambda expressions and method references.

  • So each functional interface as a single abstract method.

  • Basically, you could have one interface with multiple default methods.

  • But you must have on Lee one single abstract method to be considered as a functional into face.

  • So basically, you can see some examples right here.

  • So the assignment, the assignment context.

  • So this is how you, for example, to find a critic it and this is all, for example, you use it within the actual, you know, stream.

  • So right here you've seen that we can get stream from a list, right, so streaming and filter.

  • And there's another example where you can do some casting.

  • So this package right here contains a bunch off functional interface is right here, you see, by consumer by function, binary operator by predicated bully um, supplier consumer and the list goes on so they're pretty much identical about from the type.

  • So the ones that you will most likely be using our functions bye functions Paretti kids by predators and consumers and also there is a by consumer, but I'm But I'm gonna explain exactly how everything fits together, because once you learn those main ones, then the rest will be very simple.

  • So right here only show you that.

  • So we have a predicated.

  • So where is the pretty good?

  • So let me find credited.

  • So right here is a pretty good Let me quickly show you a credit it and surely that we actually have used, you know, predicated before.

  • So a predator represents a pretty good basically.

  • This pretty represents a predicted bullion value function off one argument.

  • So let me go back to intelligence and Ray here.

  • Remember where we had this declare it eve approach.

  • So right here.

  • So this filter.

  • So basically, if I pretty much extract this into a variable, you can see that this is a predicated.

  • And look at this.

  • This predicated looks like this.

  • So the pregnant accepts a person and then returns true or false, based off that person I eat whether the person ease off type female, right?

  • But what we've done right here, we're simply in lined like that.

  • That's why you don't see the president keyword.

  • But indeed, this is a predicated and a pretty it looks like this.