I would like to have a function which is passed some parameters (which can vary between executions of the function), but not all of them at once, then execute the function when given the rest of the parameters.
The idea is that this is the callback:
foo(argument)
But foo is customized beforehand using other parameters.
As a simple example, lets take the case of overlapping vs. non-overlapping text search. I have a function:
def textSearch(text,substring,overlapping):
...
... # Do stuff
return index
Which takes a text body, a substring, and a boolean. It searches for the substring within the body of text, using either an overlapping or non-overlapping search. I would like to be able to create an instance of the function which has a reduced callback:
textSearch(text)
By parameterizing the substring and overlapping fields before callback without having to create another function definition. The function could then be called on multiple instances of text and operate using those parameters. However, a separate instance of the function should be able to exist with different parameters at the same time.
I am given an instance of the function stored in a variable called mysearch. The function takes a text argument and returns the index of the starting character of the text within a larger text. However, I don't care if it's overlapping or non-overlapping, nor do I care what the text being searched is. I'd like to just call:
mysearch("Pancakes")
With mysearch having been parameterized beforehand as non-overlapping search of the text "Pancakes are delicious.", so the result would be 0 (the index of the start of the text).
Or maybe I am given a different configuration where it searches in an overlapping fashion, with different text. I would like to be able to call:
mysearch("Hash browns")
The idea is to keep the interface identical without having to worry about the parameters which define how the function works or rewrite the function definition. Is there a way to achieve something like this?