One-minute explanation of a monad in C#



One-minute explanation of a monad in C#

One-minute explanation of a monad in C#

A monad, in its simplest form, is the wrapper around an object of some type T.
Since I plan to use nullable references to model missing objects inside the monad, I will constrain it to be a reference type T.
In the least, a monad defines two functions.
One is to create a monad, given the object.
So, create a new monad and put the object into it.
The other function is to bind a function to the wrapped object.
The point of having the monad is to put that boilerplate code into it, so that the monad is doing other things that you would repetitively write all over your code.
That element becomes the substance of the monad you are writing.

Comments are closed.