I am trying to understand maybe Monad but most of the examples I saw used some language-specific feature. To ensure that I have gotten it conceptually right I thought of writing a generic implementation. Below is what I came up with.
Can someone tell if I have gotten it conceptually right? Is there a better way to generalize it?
def f():
return 2
def g():
return 4
def h():
return 7
def i():
return None
def bind(val, func):
if val is None:
return None
else:
return(func())
unit = 0
>>> bind(bind(bind(unit,f),i),h) #Returns nothing
>>> bind(bind(bind(unit,f),g),h) #Returns a value
>>>7
What if I wanted to add the values from these functions and abort if any of those was NULL; any suggestion?