Challenge: Parameterized Decorator
In the previous chapters, you learned about the decorator factory pattern—a technique that allows you to create decorators which themselves accept arguments. This pattern involves defining an outer function that takes the decorator arguments and returns the actual decorator, which then wraps the target function. This approach enables you to build highly flexible and reusable decorators that can be customized for different use cases.
Swipe to start coding
Write a decorator that multiplies the result of a function by a given factor, where the factor is passed as an argument to the decorator.
- The decorator must accept a single argument,
factor. - The decorator must multiply the return value of the decorated function by
factor. - The decorator must work for any function that returns a numeric value.
Solução
Obrigado pelo seu feedback!
single
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 5.88
Challenge: Parameterized Decorator
Deslize para mostrar o menu
In the previous chapters, you learned about the decorator factory pattern—a technique that allows you to create decorators which themselves accept arguments. This pattern involves defining an outer function that takes the decorator arguments and returns the actual decorator, which then wraps the target function. This approach enables you to build highly flexible and reusable decorators that can be customized for different use cases.
Swipe to start coding
Write a decorator that multiplies the result of a function by a given factor, where the factor is passed as an argument to the decorator.
- The decorator must accept a single argument,
factor. - The decorator must multiply the return value of the decorated function by
factor. - The decorator must work for any function that returns a numeric value.
Solução
Obrigado pelo seu feedback!
single