Function Addition
Description:
I often find that I end up needing to write a function to return multiple values, in this case I would often split it up into two different functions but then I have to spend time thinking of a new function name! Wouldn't it be great if I could use same name for a function again and again...
In this kata your task is to make a decorator, FuncAdd
which will allow function names to be reused and when called all functions with that name will be called (in order) and the results returned as a tuple.
def foo():
return 'Hello'
def foo():
return 'World'
foo() --> ('Hello', 'World')
As well as this you will have to implement two more things, a way of deleting a particular function, and a way of deleting all stored functions. The delete
method must work as follows:
def foo():
return 'Hello'
FuncAdd.delete(foo) # Delete all foo() functions only
foo() # Should raise NameError
And the clear
method must work like this:
def foo():
return 'Hello'
FuncAdd.clear() # Delete all decorated functions
foo() # Should raise NameError
The functions must also accept args and kwargs which would all be passed to every function.
Similar Kata:
Stats:
Created | May 14, 2020 |
Published | May 14, 2020 |
Warriors Trained | 972 |
Total Skips | 52 |
Total Code Submissions | 957 |
Total Times Completed | 195 |
Python Completions | 195 |
Total Stars | 56 |
% of votes with a positive feedback rating | 95% of 58 |
Total "Very Satisfied" Votes | 53 |
Total "Somewhat Satisfied" Votes | 4 |
Total "Not Satisfied" Votes | 1 |
Total Rank Assessments | 17 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 4 kyu |
Lowest Assessed Rank | 8 kyu |