The idea of this repo is to demonstrate that Task<T>
is a monad by comparing it to IEnumerable<T>
.
I am aiming to cover the following:
- Monad's
return
function (akaUnit
) forTask<T>
andIEnumerable<T>
- Monad's
bind
function (aka>>=
akaSelectMany
akaFlatMap
/flatMap
) forTask<T>
andIEnumerable<T>
- Functor's
fmap
function (akaSelect
) - A look at a couple of monad combinators:
sequence
- given a sequence of monads, return a single monad containing a sequence of the values obtained from the sequence of monads.- For example, given an
IEnumerable<Task<T>>
, return aTask<IEnumerable<T>>
.
- For example, given an
liftM2
- given two monads, apply a function to the two values obtained from the two monads and return the result inside a monad.- For example, given a
Task<int>
and aTask<string>
and aFunc<int, string, bool>
, return aTask<bool>
.
- For example, given a
- In C#, we need separate implementations of these monad combinators for
Task<T>
andIEnumerable<T>
but they are identical apart from the types involved. In Haskell, only a single implementation of the monad combinators is needed because the type system is more powerful (see Kind (type theory)).
- Use of LINQ query syntax with
Task<T>
just like you can do withIEnumerable<T>
- By adding implementations of
Select
andSelectMany
forTask<T>
- By adding implementations of