concept Kleisli in category .net

appears as:  Kleisli
Concurrency in .NET

This is an excerpt from Manning's book Concurrency in .NET.

13.12.1 Solution: combining asynchronous operations using the Kleisli composition operator

The composition between monadic functions is named Kleisli composition, and in FP it’s usually represented with the infix operator >=> that can be constructed using the monadic Bind operator. The Kleisli operator essentially provides a composition construct over monadic functions, which instead of composing regular functions like a -> b and b -> c, is used to compose over a -> M b and b -> M c, where M is an elevated type.

The signature of the Kleisli composition operator for elevated types, such as the Async and Task types, is

The next code snippet shows the implementation of the Kleisli operator in C#, which uses the monadic Bind operator underneath. The operator Bind (or SelectMany) for the Task type was introduced in chapter 7:

 static Func<T, Task<U>> Kleisli<T, R, U>(Func<T, Task<R>> task1, 
  Func<R, Task<U>> task2) => async value => await task1(value).Bind(task2);

!@%STYLE%@!
{"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":24},{\"line\":0,\"ch\":31}],[{\"line\":1,\"ch\":29},{\"line\":1,\"ch\":34}],[{\"line\":1,\"ch\":44},{\"line\":1,\"ch\":49}]]"}
!@%STYLE%@!