""" Hook Manager """


class HookManager(object):

    """ Registers an manages hooks. Hooks are callback functions called when the backend does a specific action. """

    def __init__(self):
        self.hooks = {}

    def add_hook(self, name, callback):
        """ Add a new hook that can be called with the call_hook function """
        hook_list = self.hooks.get(name, [])
        hook_list.append(callback)
        self.hooks[name] = hook_list

    def call_hook(self, name, **kwargs):
        """ Call all hooks registered with this name """
        for func in self.hooks.get(name, []):
            func(**kwargs)

""" Hook Manager """


class HookManager(object):

    """ Registers an manages hooks. Hooks are callback functions called when the backend does a specific action. """

    def __init__(self):
        self.hooks = {}

    def add_hook(self, name, callback):
        """ Add a new hook that can be called with the call_hook function """
        hook_list = self.hooks.get(name, [])
        hook_list.append(callback)
        self.hooks[name] = hook_list

    def call_hook(self, name, **kwargs):
        """ Call all hooks registered with this name. Returns a list of the returns values of the hooks (in the order the hooks were added)"""
        return map(lambda x: x(**kwargs), self.hooks.get(name, []))

Allow hooks to return values (and simplify the code)
Allow hooks to return values (and simplify the code)

  """ Hook Manager """
  
  
  class HookManager(object):
  
      """ Registers an manages hooks. Hooks are callback functions called when the backend does a specific action. """
  
      def __init__(self):
          self.hooks = {}
  
      def add_hook(self, name, callback):
          """ Add a new hook that can be called with the call_hook function """
          hook_list = self.hooks.get(name, [])
          hook_list.append(callback)
          self.hooks[name] = hook_list
  
      def call_hook(self, name, **kwargs):
+         """ Call all hooks registered with this name. Returns a list of the returns values of the hooks (in the order the hooks were added)"""
+         return map(lambda x: x(**kwargs), self.hooks.get(name, []))
-         """ Call all hooks registered with this name """
-         for func in self.hooks.get(name, []):
-             func(**kwargs)
  
Allow hooks to return values (and simplify the code)
## Code Before:
""" Hook Manager """


class HookManager(object):

    """ Registers an manages hooks. Hooks are callback functions called when the backend does a specific action. """

    def __init__(self):
        self.hooks = {}

    def add_hook(self, name, callback):
        """ Add a new hook that can be called with the call_hook function """
        hook_list = self.hooks.get(name, [])
        hook_list.append(callback)
        self.hooks[name] = hook_list

    def call_hook(self, name, **kwargs):
        """ Call all hooks registered with this name """
        for func in self.hooks.get(name, []):
            func(**kwargs)

## Instruction:
Allow hooks to return values (and simplify the code)
## Code After:
""" Hook Manager """


class HookManager(object):

    """ Registers an manages hooks. Hooks are callback functions called when the backend does a specific action. """

    def __init__(self):
        self.hooks = {}

    def add_hook(self, name, callback):
        """ Add a new hook that can be called with the call_hook function """
        hook_list = self.hooks.get(name, [])
        hook_list.append(callback)
        self.hooks[name] = hook_list

    def call_hook(self, name, **kwargs):
        """ Call all hooks registered with this name. Returns a list of the returns values of the hooks (in the order the hooks were added)"""
        return map(lambda x: x(**kwargs), self.hooks.get(name, []))
