I have two files in a library I am creating:
file1.py
def func1(a, b):
c = a + b
return c
file2.py
def func2(a, b):
c = a - b
return c
Now I want each file to have a function that takes the function from that file as an argument, but otherwise does the same thing. So a function like:
def new_func(f, x, y, z):
return f(x, y) * z
Since I don't want to repeat myself, I would prefer to define this function in a separate file, then use some sort of function inheritance that creates a partial function with the first argument set to the func at the beginning of that file. So users can access new_func using file1.new_func(x, y, z) and file2.new_func(x, y, z).
For context, I have many new_funcs I want to add to about a handful of files. Each would take in the func at the beginning of the file as a fixed argument, so essentially a partial function. But beyond that, they would all do the same thing with that func.
Is this possible using the functional programming paradigm?
I have Googled like crazy about function inheritance, partial functions and decorators (as I thought that might help), but have so far found nothing like what I am attempting to do.
EDIT: To be clear, the point of this question is (1) multiple files each with a single function and (2) a set of partial functions that would take in the single function as the fixed parameter, but without copying and pasting the partial functions to each file. That is why I mention inheritance, as I essentially want to do some sort of function inheritance rather than copying and pasting functions across files.