From the course: Introducing Functional Programming in C++
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Solution: Factorial continuous add - C++ Tutorial
From the course: Introducing Functional Programming in C++
Solution: Factorial continuous add
(electronic music) - [Instructor] My solution is somewhat similar to the incremental lambda we created earlier except it sets the initial value to the past initial argument and it adds the value of addBy instead of one each successive call. So let's take a look at it in code. Open up our main. We've already got our include file and our namespace. And right here we want to create auto space continuousAdd and the we have an open and closed square brace. We have our parenthesis. And we have an init integer. Initial comma integer addBy and then we're going to say that auto total equals initial. Now this step's probably not necessary but I like the purpose of all my variables to be very clear to me. Then we're going to say return. And then we want to capture total and addBy in our scope. Then we have take no variables here. And we're going to say that this is mutable. Because we're going to change the value of total. And then we're going to do a total plus equals addBy. And finally we'll…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Enabling C++ 174m 24s
-
(Locked)
transform instead of map5m 30s
-
(Locked)
copy_if instead of filter2m 59s
-
(Locked)
accumulate instead of reduce2m 51s
-
(Locked)
bind4m 56s
-
(Locked)
Functions6m 54s
-
(Locked)
Lambda functions: Curry3m 38s
-
(Locked)
Lambda functions: Closures2m 20s
-
(Locked)
Challenge: Factorial continuous add33s
-
(Locked)
Solution: Factorial continuous add3m 15s
-
(Locked)
-
-
-