Skip to content

Instantly share code, notes, and snippets.

@fwfurtado
Created August 8, 2018 15:45
Show Gist options
  • Save fwfurtado/59727e673dd9fd51edd55bbdf4939512 to your computer and use it in GitHub Desktop.
Save fwfurtado/59727e673dd9fd51edd55bbdf4939512 to your computer and use it in GitHub Desktop.
class Strategy:
registered = []
def __init__(self, func):
self._func = func
Strategy.registered.append(func)
def __call__(self, *args, **kwargs):
return self._func(*args, **kwargs)
from strategy import Strategy
@Strategy
def strategy_1(x, y):
return x + y
@Strategy
def strategy_2(x, y):
return x - y
print(Strategy.registered)

Sample of strategy with registration in import time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment