Skip to content

Instantly share code, notes, and snippets.

@dustingetz
Created May 10, 2012 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustingetz/2653752 to your computer and use it in GitHub Desktop.
Save dustingetz/2653752 to your computer and use it in GitHub Desktop.
def get_account(name):
if name == "Irek": return 1, None
elif name == "John": return 2, None
elif name == "Alex": return 3, None
elif name == "Nick": return 1, None
else: return None, "No account associated with name '%s'" % name
def get_balance(account):
if account == 1: return 1000000, None
elif account == 2: return 75000, None
else: return None, "No balance associated with account #%s" % account
def get_loan(balance):
if balance > 200000: return balance, None
else: return None, "Insufficient funds for loan, current balance is %s" % balance
def bind(mval, mf):
value = mval[0]
error = mval[1]
if not error:
return mf(value)
else:
return mval
def unit(value):
return value, None
# business logic
def get_loan2(name):
return bind(get_account(name), lambda account:
bind(get_balance(account), lambda balance:
bind(get_loan(balance), lambda loan:
unit(loan)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment