Created
May 10, 2012 15:06
-
-
Save dustingetz/2653752 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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