Closed sebastialonso closed 5 years ago
Maybe it's not really explicit from the docs, but having a function decorated multiple times actually works:
@decorate innerdecorator()
@decorate middledecorator()
@decorate outerdecorator(:arg)
def func1(x) do
x
end
I'm noticing some warnings being generated sometimes, I'll see what I can do about those
Thanks @arjan!. After trying some examples I have found that decorators are indeed stackable.
In your decorators, does outerdecorator
"calls" middledecorator and innerdecorator
? More generally, is the inner most decorator called many times?
I'm just lazy printing flags and they are inconsistent most of the times.
No, they just "chain". So the body
that the middle decorator gets is the original body with the innerdecorator applied; likewise, the body that the outer decorator gets is middle(inner(body))
I think "composable" is a better word for this behaviour. Remember, in runtime all of this is gone.
Awesome, thanks!
First of all, thank you for this neat library.
Just out of curiosity, is the current implementation able to stack and execute several decorators for a single function?