Function that operates on a data type (or set)
Laws:
- Associative, eg.
2 + 3 <=> 3 + 2
- Binary Operations, eg.
public static Foo Op(Foo x, Foo y)
- With a neutral element (identity), eg.
2 + 3 + 0 <=> 3 + 2 + 0
Examples:
- Maybe
- Endomorphism
- Tuple
- Either
Laws:
- Binary Operation
- Associative
- No identity required
Examples:
- Min / Max
- First / Last
- Aggregation
Laws:
- Inversion
- No associativity required
- No identity required
Example: substraction
Law: binary operation with no constraints on its behaviour
Examples:
- Rock, paper, scissors
- Colour Mixing
Collection of objects / points with morphisms (ie. functions, transformations) between them:
f: a -> b
g: b -> c
g.f: a -> c
Btw, composition is associative: h.(g.f) = (h.g).f
A functor F
is a mapping between 2 categories, not only between their objects but also between their morphisms.
Laws:
f: a -> b
F(f): F(a) -> F(b)
Functor from a category to itself.
Monoids in the category of endofunctors
Basically a monad in the C# context, is a type that gives some additional features to an 1-ary generic type T
.
Examples:
IEnumerable<T>
: givesT
non-determinism (multiple values)Nullable<T>
: givesT
nullabilityTask<T>
: givesT
asynchronicity
To resp. play with them and get the inner value:
- LINQ
??
orGetValue
await
In other languages like F# or Haskell, you could define two methods to create a new monad, in C# it would look like:
public static Monad<T> Return<T>(T value)
public static Monad<U> Bind<T, U>(Monad<T> value, Func<T, Monad<U>> operation)