I'm working on a validation library containing a number of validators. Each validator is curried with a message as the first argument followed by any configuration values.
A user of the library can pass in a map of message functions which will be applied to the validators by the library.
const configuredValidators = Lib.configure(messages);
If using these validators without this configuration step, they can just be imported into whichever file needs them:
import { exampleValidator } from 'lib'
However by preconfiguring the validators, a user of the library now needs to pass these validators around to whichever function needs them. If these functions are a long way from the point of configuration, every function in between now needs to add an argument to pass through the configured validator(s).
When adopting as OO approach there are a number of solutions to this problem, but what is the functional solution? How can I make these partially applied validators available throughout the application without a user needing to muddy the signatures of many other functions?
I understand that reaching out from within a function to an external variable raises issues of purity, but I suppose I'm looking for the convenience of an import, but with functions that have had values partially applied at runtime.
Note: For the purposes of this question, assume the users of the library will be adopting a functional approach.