Skip to content

taylorjg/MonadDemo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Description

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 (aka Unit) for Task<T> and IEnumerable<T>
  • Monad's bind function (aka >>= aka SelectMany aka FlatMap/flatMap) for Task<T> and IEnumerable<T>
  • Functor's fmap function (aka Select)
  • 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 a Task<IEnumerable<T>>.
    • 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 a Task<string> and a Func<int, string, bool>, return a Task<bool>.
    • In C#, we need separate implementations of these monad combinators for Task<T> and IEnumerable<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 with IEnumerable<T>
    • By adding implementations of Select and SelectMany for Task<T>

Links

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages