On 27 January 2018 at 08:33, horrido <
[hidden email]> wrote:
> Is there a Pharo equivalent to Ruby's Maybe monad? See
>
https://github.com/rap1ds/ruby-possiblyFrom that page I read...
"Maybe monad is a programming pattern that allows to treat nil
values that same way as non-nil values"
At a minimum you can just define required methods on UndefinedObject.
For example...
UndefinedObject >> myThing
self inform: 'Nil does my thing!!'
then in Playground evaluate...
nil myThing
This obviously doesn't cover the "Some" part of Maybe-monad,
but you didn't provide any description of what you're trying to do so
I don't know how important that is to you.
However, in general a better approach than adding methods to
UndefinedObject if to use the Null pattern.
Initialize your variables with an instance of MyDomainNull which
defines the minimum required messages to avoid DNUs.
Such a class might fit as the root superclass of all your domain classes.
But this suggestion might be off target, since I can't grok where I'd
use something like Maybe-Monad in my own programming.
cheers -ben