Package: bindpy
bindpyThe bindpy package allows for partial application of arguments to a function, making it easy to create specialized versions of the function with some arguments pre-filled.
It is a better version of the Python's standardpartialfunction from thefunctoolspackage inspired by C++'sstd::bind.InstallExpect gracefully crafted support for any version of Python 3+, but confidently tested in version 3.7 and higher.pip install bindpyUsagefrombindpyimport*bindfunctionTheshowfunction takes three arguments,a1,a2anda3, and returns a string composed of their values separated by spaces. Theshow_10function is a partially applied version ofshow, witha2bound to_1,a1bound to_2anda3bound to10.Bind support placeholders :_1,_2, ..._10. The placeholders allow you to partially apply a function and leave certain arguments to be filled in later. This allows you to reuse the partially applied function and pass different values for the placeholder argument.Overall,bindand placeholders make it easier to create reusable and composable functions by allowing you to fix certain arguments and create new functions that take fewer arguments.defshow(a1,a2,a3):return" ".join(map(str,[a1,a2,a3]))show_10=bind(show,_2,_1,a3=10)print(show_10(20,30))# output: 30 20 10Convenient to use with functional style.If you find lambda expressions unappealing, you can use bind for a more convenient and aesthetically pleasing experience with functional programming.defadd(a,b,c):returna+b*cnumbers=[1,2,3,4]print(list(map(bind(add,_1,10,2),numbers)))# output 21 22 23 24# same code with lambdaprint(list(map(lambdax:add(x,10,2),numbers)))importos# used for examplefiles=['a.txt','b.json']my_join=bind(os.path.join,'.','data')print(list(map(my_join,files)))# output ['./data/a.txt', './data/b.json']bind_frontfunctionbind_frontpre-specifies function arguments likefunctools.partial. It takes a function and values, returns new function with values bound to front. When called with remaining args, values passed tobind_frontare automatically inserted in front.defadd(a,b,c=0):returna+b+cadd_10=bind_front(add,10)result=add_10(20,c=30)print(result)# 60add_20_30=bind_front(add,20,30)result=add_20_30()# call add(20, 30)print(result)# 50bind_backfunctionbind_backalso pre-specifies function arguments but with values bound to end of arg list after all others. It takes a function and key-value pairs, returns new function with values bound to end. When called with remaining args, values passed tobind_backare automatically inserted at end.add_30=bind_back(add,c=30)result=add_30(10,20)print(result)# 60add_40=bind_back(add,40)result=add_40(10,20)# call add(10, 20, 40)print(result)# 70add_10=bind_back(add,10)result=add_10(12)# call add(10, 12), c=0 by  defaultprint(result)# 22sequential bindingYou can combinebind_frontandbind_backto create a function that has arguments pre-specified at both the front and end of the argument list.
For example, the code:deffunc(p1,p2,p3,p4,p5):return" ".join(map(str,[p1,p2,p3,p4,p5]))b_func=bind_front(bind_back(func,4,5),1,2)print(bfunc(3))# 1 2 3 4 5can be replaced with:b_func_v2=bind(1,2,_1,4,5)# using placeholder *_1*print(bfunc(3))# 1 2 3 4 5We hope this information helps you effectively use the bind functions in your project. If you have any questions or feedback, please reach out to us. Happy coding!AcknowledgementsWe would like to express our sincere gratitude to all the individuals who have made this project a reality. Their contributions, guidance, and support have been invaluable. Thank you to everyone who has played a part in bringing this project to life.Daniil DudkinChatGPT