Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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)
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:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.