New Feature: Built-in and custom decorators
Closed this issue · 2 comments
Decorators
The ability to "insert" both built-in (part of Ask) and user-made code/functionality into functions.
Usage
Decorating a function and/or route
&[decorator goes here]
def [function]([params]): # OR: @[method]([route]):
Creating a decorator
decorator [decorator name goes here]:
# Code goes here...
...
Simple Example
decorator my_first_decorator:
print('Before')
_inner()
print('After')
&my_first_decorator
def my_function(message):
print(message)
my_function('Hello')
Transpiled result
...
def my_first_decorator(func):
def wrapper(*args, *kwargs):
print('Before')
func(*args, *kwargs)
return wrapper
@my_first_decorator
def my_function(message):
print(message)
my_function('Hello')
...
Output
Before
Hello
After
Ideas
Can I do that by creating a template_dict that will store lambda function ?
And a function will call this template if he finds his name as a key inside ?
Can I do that by creating a template_dict that will store lambda function ?
And a function will call this template if he finds his name as a key inside ?
I think lambdas might be a bit too simple in this case. I would like to make multiple line/function/class templates, basically, whole parts of scripts and that would be really hard to implement with single-line lambdas.
What I had in mind was to generate decorator & first-class functions to achieve this.