From the course: Functional Programming with Java

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Composition

Composition - Java Tutorial

From the course: Functional Programming with Java

Start my 1-month free trial

Composition

- [Instructor] The last advanced functional concept that we're going to look at in this course, is something called composition. So, roughly speaking, composition is when we take a series of smaller modular functions and we combine them into one more complex function. A simple example of this would be if we took some very simple mathematical function, such as doubling or subtracting one from a number. And then we combined them into a more complex mathematical function. So, for example, here, we're taking the functions X times two, and X minus one and combining them into the function, two X minus one. So, that's the basic concept of composition. Why don't we head over to our IDE and take a look at what this actually is going to look like in code. So, let's define these two functions here. So, we'll have one function takes an integer as an argument and returns an integer. And we'll call this times two. And it's simply going to take an argument and return that argument times two. And…

Contents