Created
February 7, 2020 06:27
-
-
Save arpitbbhayani/e61b7fa79b619e6f0fdba506c06e3b14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Namespace(object): | |
"""Namespace is the singleton class that is responsible | |
for holding all the functions. | |
""" | |
__instance = None | |
def __init__(self): | |
if self.__instance is None: | |
self.function_map = dict() | |
Namespace.__instance = self | |
else: | |
raise Exception("cannot instantiate a virtual Namespace again") | |
@staticmethod | |
def get_instance(): | |
if Namespace.__instance is None: | |
Namespace() | |
return Namespace.__instance | |
def register(self, fn): | |
"""registers the function in the virtual namespace and returns | |
an instance of callable Function that wraps the | |
function fn. | |
""" | |
func = Function(fn) | |
self.function_map[func.key()] = fn | |
return func |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment