ELI5: Explain Like I'm 5

Function composition (computer science)

Function composition in computer science is like playing with Legos. Just like how you can connect different Lego pieces to make different structures, you can connect different functions in computer code to make new functions.

Let's say one function is like a Lego piece that takes in a number and multiplies it by 2. Another function is like another Lego piece that takes in a string and adds "hello" to the beginning.

Now, if you want to make a new function that takes in a number, multiplies it by 2, and then adds "hello" to the beginning, you can use function composition to connect these two functions together.

So you start with the original number, pass it through the first function which doubles it, and then pass the result of that operation to the second function which adds "hello" to the beginning of it.

The end result is a new function that takes a number, multiplies it by 2, and adds "hello" to the beginning. This is like building a new Lego structure by connecting different Lego pieces!