Trying to find a way to clean up some of my code.
So, I have something like this in my Python code:
company = None
country = None
person = Person.find(id=12345)
if person is not None: # found
company = Company.find(person.companyId)
if company is not None:
country = Country.find(company.countryId)
return (person, company, country)
Having read a tutorial on Haskell's monads (in particular Maybe), I was wondering if it's possible to write it in another way.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…