Decorators

Clio supports function decorators. If you’re familiar with the concept of decorators in Python, you already know their use cases and know how they work. Function decorators, are functions that take in a function as their last parameter, and return another function. This has a lot of interesting use cases, and is used by the Clio compiler to add a few interesting features:

The log function in the above example is a decorator, it takes in a function as its last parameter, then wraps it in a new function and returns this new function. On line 6, @log decorates the hello function with the log function. Click on run to see what happens.

As said earlier, decorators have lots of interesting use cases, for example, when used together with the Node.js express library, the following can be accomplished:

Note

To run the above example you need to add express to your dependencies: clio deps add --npm express

You can also document your functions with @describe:

Using the help function on any function prints the documentation for that function, if it exists. In addition to that, the clio docs command can be used to view documentation for the functions defined in a project: