Hacker News new | past | comments | ask | show | jobs | submit login

Something like this?

  class matching:
      def __init__(self, expr):
          self.expr = expr
          self.patterns = []
          self.result = None
  
      def __call__(self, pattern):
          def _inner(func):
              self.patterns.append((pattern, func))
              return func
          return _inner
  
      def __enter__(self):
          return self
  
      def __exit__(self, *args):
          for pattern, func in self.patterns:
              if pattern.match(self.expr):
                  self.result = func(self.expr)



Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: