Skip to content

Instantly share code, notes, and snippets.

@arpitbbhayani
Created February 7, 2020 06:27
Show Gist options
  • Save arpitbbhayani/e61b7fa79b619e6f0fdba506c06e3b14 to your computer and use it in GitHub Desktop.
Save arpitbbhayani/e61b7fa79b619e6f0fdba506c06e3b14 to your computer and use it in GitHub Desktop.
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