5 kyu

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.

@FuncAdd
def foo():
    return 'Hello'

@FuncAdd
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:

@FuncAdd
def foo():
    return 'Hello'
    
FuncAdd.delete(foo) # Delete all foo() functions only
foo() # Should raise NameError

And the clear method must work like this:

@FuncAdd
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.

Fundamentals

Stats:

CreatedMay 14, 2020
PublishedMay 14, 2020
Warriors Trained972
Total Skips52
Total Code Submissions957
Total Times Completed195
Python Completions195
Total Stars56
% of votes with a positive feedback rating95% of 58
Total "Very Satisfied" Votes53
Total "Somewhat Satisfied" Votes4
Total "Not Satisfied" Votes1
Total Rank Assessments17
Average Assessed Rank
5 kyu
Highest Assessed Rank
4 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • wookie184 Avatar
  • ozichukwu Avatar
  • user8436785 Avatar
Ad