This is a perfect introduction and use of the Maybe monad. I'm so grateful for the clarification of Maybe - I hope everyone in JS reads this!
The intro is great. It's exactly an interface with expected behavior. Very nice way to describe these burritos. The end is fun too!
Here's what I got:
I think calling Humble a data structure or the "Maybe+Humble monad" is a stretch - even with the "technically it's not a monad by itself" note. It is a standard monadic function (or kleisli arrow if you like): a -> M a where M is a monad. safeProp is a monadic function as well. They are just two damn good examples of using Maybe in action. The egoChange example breaks out of the null-check box and demonstrates usage very well.
ap is technically part of the Applicative (aka Apply) interface, but every Monad is an Applicative so the point is moot. Could be a note, might not matter. Just sayin' :)
Maybe.of( x ) instead of Just( x ) in the definitions of Humble and safeProp are a bit unidiomatic. of is usually reserved for when we need a generic way to place a value in a type and start chaining away - exactly how you do in the safeProp usage. Since we don't really need to program to an interface and the intent may be a little clearer with Nothing/Just vs Nothing/of, it might be good to change. However, I see why you might want to avoid juggling 3 constructors while teaching...
Good feedback here, thanks. I reworked the appendix a fair bit to try and make its details clearer. On reading, I think this feedback has been addressed sufficiently.
This is a perfect introduction and use of the Maybe monad. I'm so grateful for the clarification of
Maybe
- I hope everyone in JS reads this!The intro is great. It's exactly an interface with expected behavior. Very nice way to describe these burritos. The end is fun too!
Here's what I got:
I think calling
Humble
a data structure or the "Maybe+Humble monad" is a stretch - even with the "technically it's not a monad by itself" note. It is a standard monadic function (or kleisli arrow if you like):a -> M a
whereM
is a monad.safeProp
is a monadic function as well. They are just two damn good examples of usingMaybe
in action. TheegoChange
example breaks out of the null-check box and demonstrates usage very well.ap
is technically part of the Applicative (aka Apply) interface, but every Monad is an Applicative so the point is moot. Could be a note, might not matter. Just sayin' :)Maybe.of( x )
instead ofJust( x )
in the definitions ofHumble
andsafeProp
are a bit unidiomatic.of
is usually reserved for when we need a generic way to place a value in a type and startchain
ing away - exactly how you do in thesafeProp
usage. Since we don't really need to program to an interface and the intent may be a little clearer withNothing/Just
vsNothing/of
, it might be good to change. However, I see why you might want to avoid juggling 3 constructors while teaching...