Skip to content

Instantly share code, notes, and snippets.

@ibizaman
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save ibizaman/1ff9a8092f4bbac79292 to your computer and use it in GitHub Desktop.

Select an option

Save ibizaman/1ff9a8092f4bbac79292 to your computer and use it in GitHub Desktop.
Error log as applicative function
class MyClass:
def __init__(self):
self.errors = []
self.warnings = []
def apply(self, function, *args):
result, self.errors, self.warnings = function(*args, errors=self.errors, warnings=self.warnings)
return result
def applicative_functor_style(self, ast):
a = self.apply(f_a, ast)
b = self.apply(f_b, a)
def old_way(self, ast):
a, self.errors, self.warnings = f_a(ast, self.errors, self.warnings)
b, self.errors, self.warnings = f_b(a, self.errors, self.warnings)
def f_a(ast, errors, warnings):
# compute
errors.append('Error #1')
# compute
warnings.append('Warning #1')
# compute
result = #...
return (result, errors, warnings)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment