Monad Design Pattern (C#)

preview_player
Показать описание
Explanation of Monad using C#. Monads have 2 sides to them: 1. storing a value 2. applying functions to stored value. This gives us function composition between functions that return a monad value and a function that takes the contained value within the monad. The function application mechanism of the monad knows how to pass the stored value in to the supplied function. This pattern brings automatic handling of nulls/awaits/try or any other effect in between function composition. The end result is a clear problem that you are trying to solve free of edge cases.

more resource Monads:

#csharp #monad #designpatterns
Рекомендации по теме
Комментарии
Автор

I wonder if this is used in general practise. I personally couldn't agree more with your advice, but I do wonder if it's the best way to go from an OO perspective. Could you elaborate on how the usage of monads in combination with the Nil<T> structure, lead to a better and more maintainable process? I am a fan of process composition, but I don't see how this could be implemented in smaller processes. 100 Points to Griffindor for the self describing code and the abstracting away of NULL. But you didn't remove NULL, you just gave it a wrapper so you could treat it in a different way. NULL will eventually still be in your code, you just don't deal with NULL but rather an object that represents having no value.

LordErnie
Автор

I was waiting for your video for Functional Programming damn i am so happy.

aamirali
Автор

I realize I'm spoiled as a programmer; we have lots of memory and horsepower to work with nowadays, but my brain really likes the clear class and type definitions that Object Oriented Programming offers. Functional programming is great with C/C++ (particularly on microcontrollers) but on larger systems it can be incredibly difficult to maintain Functional code if you didn't write it. Imagine stepping through even a few thousand lines of this after you've been given an old project. Literal nightmare.

jakemeyer
Автор

Watching this in 0.75 speed helps understand this a lot better.

alexintel
Автор

How do you handle code that throws exceptions inside the monad

health_doc
Автор

This reminds a bit of fluent pattern and pipes. Am I saying nonsense ?

vamvdotnet
Автор

Could you please start using Microsoft's C# Coding Conventions (especially in naming)? Thank you.

Haapavuo