What is advantage of bind function adapter? | SoloLearn: Learn to code for FREE!

+1

What is advantage of bind function adapter?

Hi I could not find proper use case of bind. I have created a below sample code for same : https://code.sololearn.com/cgTGWZ4Bh7vT/?ref=app What my concern is need of bind. Whatever I am doing using bind is achieved with default argument. Is there something else I am missing for bind's importance?

5/20/2020 5:38:47 PM

Ketan Lalcheta

2 Answers

New Answer

+4

Often examples that show how to use something are made very simple to help get the point across. Think beyond the use of simple cases. Say you had a function that took in several different types of objects making the function call long and you were going to use it several times throughout your code, but maybe most of the calls would be using a majority of the same objects for each call to that function. This could be used, instead of creating a while new function, as a wrapper so that the repetitive objects passed didn't need to be used with each function call, and instead just pass only the objects that are unique for that call. The example is basically the same as funcAdapter(int x) { return add(1, x); } https://www.google.com/amp/s/www.geeksforgeeks.org/bind-function-placeholders-c/amp/

+4

This is a very important concept in functional programming, also known as partial application of a function. It transforms a binary function (one that takes two parameters) into an unary function (single parameter). This can be extremely useful when dealing with higher order functions. I know C++ is not particularly functional language but it also has corresponding functions of filter, map, reduce. For an actual use case, you can look at my python example.. https://code.sololearn.com/cBZ8CthiaJ8h/?ref=app