# Option

It is an *either-of* algebraic type. It is either Something (a value) or Nothing (no value).

enum Option<T> { Some(T), None, }

Just this, *type-tagget* mutually exclusive variants *only*. No monadic bullshit.

The *zero-value* of a type is the same core concept - there is a *zero* which stands for nothing (a result of `1 - 1`

).

There is no shortage of various option types. The dogma (or meme) behind them is to avoid *null-propagation*. A well-defined *zero-value* for each type (as in Go is the right way.

The most famous type is, of course, a *Maybe*.

data Maybe a = Nothing | Just a

If we implement the monad interface we would have a *Maybe Monad*

instance Monad Maybe where (Just x) >>= k = k x Nothing >>= _ = Nothing (>>) = (*>) fail _ = Nothing

where

Just _m1 *> m2 = m2 Nothing *> _m2 = Nothing

Or just simply an enumeration of variants

enum Option<T> { None, Some(T), }

**Note:**See TracWiki for help on using the wiki.