i2mint / i2

Python Mint creation, manipulation, and use
Apache License 2.0
2 stars 1 forks source link

`Wrapx`: Extending `Wrap` to cover more wrapper patterns. #18

Closed thorwhalen closed 2 years ago

thorwhalen commented 2 years ago

Currently, Wrap is an object that can encapsulate all wrapping cases where one or several of the following happens:

image

But this doesn't cover situations where the wrapped function call may need to be modified, or the output trans need to be controlled from the interface. For example:

Following are some structural ideas for this extension of Wrap.

Sourcing from user input with call_forgivingly

    def __call__(self, *args, **kwargs):
        inner_input_dict = self.sig.kwargs_from_args_and_kwargs(args, kwargs)
        func_args, func_kwargs = call_forgivingly(self.ingress, **inner_input_dict)
        inner_output = call_forgivingly(self.func, *func_args, **func_kwargs)
        return call_forgivingly(self.egress, inner_output, **inner_input_dict)
image

Repurpose ingress

image

Factory layer

image

can be written (or at least subsumed) by this:

image

If we add the following "factories layer" to that:

image

we get:

image

More direct alternative

image