The Absolute Best Intro to Monads For Software Engineers

2024 ж. 9 Мам.
542 514 Рет қаралды

If you had to pick the most inaccessible terms in all of software engineering, monad would be a strong contender for first place, because of its spooky math background that uses terms like endofunctor and monoid. As it turns out, monads are an extremely powerful design pattern that can be used without any math knowledge. In this video, we’ll cover what monads are, how they can be incredibly useful, and examine some common monads. All you need is a little software engineering knowledge. Let's go!
Dr. Strange Icon Credit: dribbble.com/dalius-stuoka
00:00 Intro
00:29 Basic Code
01:45 Issue #1
02:38 Issue #2
04:11 Putting It All Together
05:15 Properties of Monads
06:05 The Option Monad
09:14 Monads Hide Work Behind The Scenes
11:21 Common Monads
12:10 The List Monad
13:56 Recap

Пікірлер
  • Hands down the most awesome explanation of Monads on KZhead

    @asadsalehumar1011@asadsalehumar10112 жыл бұрын
    • My experience as well, though I realise as much having already understood the concept via classic methods (see a book on Haskell), so I was like "Yep, that's totally it". I doubt it would have helped me if I had used it as tutorial material. Still, a stellar explanation

      @neogen23@neogen23 Жыл бұрын
    • It turns out that we have been using monads without even knowing it for years.XD

      @AutoFirePad@AutoFirePad Жыл бұрын
    • Feel you

      @erikkostic8271@erikkostic827111 ай бұрын
    • Agree

      @stopper0203@stopper020311 ай бұрын
    • Maybe it was. I gave up when I heard the stupid music.

      @quantisedspace7047@quantisedspace70478 ай бұрын
  • How on earth did you break the curse!? .... "Once you understand Monads you lose the ability to explain them"! 🤣

    @jcolt452@jcolt4522 жыл бұрын
    • you have to trick a veteran functional programmer into helping you if you start explaining monads to enough people that already understand them, eventually one will tell you 'oh you don't _actually really_ understand monads unless you understand…' and suddenly you will feel this clearness in your brain you can suddenly explain this concept and all of the useful ramifications

      @aiocafea@aiocafea Жыл бұрын
    • I think that's true for most coding problems ;)

      @Bergerons_Review@Bergerons_Review Жыл бұрын
    • This is greate video that explain how to use monads and how fo recognize them, but in true math style there is whole universe that you skiped.

      @GesteromTV@GesteromTV7 ай бұрын
    • @@GesteromTVAnd that's how he shoved it into a 15-minute video, and not a 60-minute lecture 😝

      @ArturCzajka@ArturCzajka7 ай бұрын
    • Monads are a brain virus which makes you believe in Monads

      @Lee-qj4hk@Lee-qj4hk7 ай бұрын
  • After maybe 10 years of periodically going back to the definition of monads, googling and still not understanding what the hell they are, you have done it! Thank you, one less mystery in life.

    @gargshishir3@gargshishir3 Жыл бұрын
    • I watched this video last year, and this year, I already do not remember what it is. Time to watch this video again. :)

      @KingTheRat@KingTheRat7 ай бұрын
    • @@KingTheRat I did that recently too 😆

      @gargshishir3@gargshishir37 ай бұрын
  • That was fun to watch. I've been writing rust for a good while now, so basically I've been using monads everyday all this time without knowing the concept's technical name. Watching you refactor bad typescript step by step into rust felt funny.

    @scheimong@scheimong Жыл бұрын
    • And this explains why don't understand Rust... I didn't understand monads!

      @ChrisD__@ChrisD__ Жыл бұрын
  • Very good explanation, finally someone who's using a programming language which people who don't yet know what monads are can actually understand. Another good video on the subject is Brian Beckman's "Don't fear the Monad" which explains it in a more abstract way, but still using familiar terms. Other videos, and especially Computerphile's video were completely inaccessible to me and left me thinking that I'd need to spend months studying category theory or at least read a book on Haskell before I could understand this concept. You and Brian made me realize that I had actually invented monads on my own and have been using them without knowing what they are.

    @nobodyinparticular8219@nobodyinparticular82192 жыл бұрын
    • I'm not familiar with this programming language. What language is this?

      @evanroderick91@evanroderick91 Жыл бұрын
    • @@evanroderick91 I think this is typescript

      @rakandhiyaaa92@rakandhiyaaa92 Жыл бұрын
    • @@evanroderick91 as mentioned before it is TypeScript: JavaScript but with types

      @younes3573@younes3573 Жыл бұрын
    • I agree with you about video ‚Dont fear the monad’. Also explains it really well

      @denisg1208@denisg1208 Жыл бұрын
    • It's funny you mentioned the computerphile video because I likewise, even in using monads wherever applicable, watched that video and felt like I understood it even less. Even funnier still is the disclaimer he gave of "well people criticize mathematicians for not being able to explain their concepts in relatable terms, but I think they should just get over it". And it's like... they will get over it, by just ignoring their work & having to rediscover it anyways in their own contexts.

      @MrRedstonefreedom@MrRedstonefreedom Жыл бұрын
  • Thank you. this video is very practical, informative, and truly demonstrates what can be achieved with monad with actual example and not just the abstract concepts of it all. Best one yet that I've seen on KZhead. You've earned a new. subscriber!

    @chachan4142@chachan4142 Жыл бұрын
  • first video that actually explains monads in sensible approachable way. thank u very much

    @JoshuaKisb@JoshuaKisb2 жыл бұрын
  • Dude. This was fucking sick, please keep producing videos like this. I think there's also a lack of beautiful visualisations for more advanced concepts (which makes sense because more people are going to be beginners). Keep it up man, your animations are absolutely gorgeous :)

    @connorkapooh2002@connorkapooh2002 Жыл бұрын
  • I loved this video. Would love to see some explanations on applicatives and functors as well and some fp-ts examples. The pipe and flow makes using monads and functors so nice

    @brettm4179@brettm41792 жыл бұрын
  • I'm blind and you were able to describe your content without using this and that while pointing at places in the code. nice work.

    @CFEF44AB1399978B0011@CFEF44AB1399978B00117 ай бұрын
    • bro WDYM YOU ARE BLIND AND WATCHING KZhead

      @steveloco1170@steveloco11707 ай бұрын
    • @@steveloco1170 you do realize blind people live normal lives?

      @CFEF44AB1399978B0011@CFEF44AB1399978B00117 ай бұрын
    • @@steveloco1170 main thing to know is "blind" is shorthand for visually impaired. Also you can learn from hearing too.

      @jhoughjr1@jhoughjr17 ай бұрын
  • Jesus, this is such a robust explanation. This could be watched every 3 months just to reconsider newly-encountered applicability. I already came to the same conclusions about monads in programming (as a design pattern, in any kind of paradigm or language), and done a lot of deep thinking, but even still, this is such a wildly useful video as a consolidation tool. You've given a lot of excellent visualizations that make aspects-management & its expression a lot easier.

    @MrRedstonefreedom@MrRedstonefreedom Жыл бұрын
  • By far the most amazing explanation i've ever read. Nice examples, made the concept a lot easier to understand!

    @GVSM-xo9ri@GVSM-xo9ri Жыл бұрын
  • Amazing work here. Turns out I've been partially harnessing the power of monads the whole time, but understanding how you can simply chain passed functions brings my software engineering understanding to a new level. Thanks for your effort in making this video Alex.

    @blakedowling7002@blakedowling70026 ай бұрын
  • This seems like a very intuitive pattern but at the same time I never knew this could be so formalized. Thank you I learned a lot

    @youngcitybandit@youngcitybandit7 ай бұрын
  • +1, this video taught me exactly what monads are from a practical standpoint. Thank you!

    @arongil@arongil Жыл бұрын
  • As someone who didn't know monads, this is an excellent video! You started with an iterative approach on simple examples to give an intuition of why the idea of monads is useful. Then after having the intuition you give a more abstract, rigorous definition, along with real usages. I think I wouldnt have been able to understand the abstraction as easily if there wasnt the simple examples in the beginning. Then you give a summary to help remember the content of this video. Overall I think the flow is great and the pace is just right. Sometimes I have to pause a bit to understand the code but I never have to think really hard to understand since the leaps in logic are always small enough. Thank you for making this video!

    @papetoast@papetoast Жыл бұрын
  • I've always thought that the definitions people used are always more complex than they need to be. I'm glad you've managed to explain it in a way that feels like something a programmer would do

    @erikgrundy@erikgrundy Жыл бұрын
    • By programmer you mean code 🐒

      @user-tx4wj7qk4t@user-tx4wj7qk4tАй бұрын
    • @@user-tx4wj7qk4t i don't, and i'm a little confused at what you're implying. do you mean that no "real" programmer requires it to be explained like this? or that you don't think the code in the video is very good? please, enlighten me

      @erikgrundy@erikgrundyАй бұрын
    • @@erikgrundy a software engineer is supposed to be an engineer. An engineer uses math and science to solve real life problems. However "software engineers" are the only kind of engineers who hate math and science and think even simple basic math is "too complex" and are always looking for immediate answers on "how" to use something, with very little understanding of "what" something is or "why" it is. The explanation above is terrible for very many reasons but mainly because he doesn't actually explain anything any what a monad actually is, it's just overly convoluted examples of what you can do with it which ironically is more complex than if somebody just explained what it is. You saying "feels like something a programmer would do" means code monkey because actual software engineers understand math and don't explain things this way

      @user-tx4wj7qk4t@user-tx4wj7qk4tАй бұрын
  • This is some good stuff. I'm also glad to see you have other videos. Hoping you get more subscribers, you deserve it

    @vikingthedude@vikingthedude Жыл бұрын
  • You won yourself a subscriber with this clean clean video. Can't wait to go through more of your content!

    @Masto12321@Masto12321 Жыл бұрын
  • This is one of the best explanations I've ever seen. Thanks a lot

    @romanmahotskyi6898@romanmahotskyi6898 Жыл бұрын
  • One of the best videos on programming I've ever seen. Subscribed. Please make more!

    @therealguanzo@therealguanzo Жыл бұрын
  • Please keep coming up with great content like this, thank you!

    @sct848@sct848 Жыл бұрын
  • I've been doing this for years and just calling it good encapsulation and treating functions as a blackbox. Reduce how much the caller needs to know about the function and allow it to be a blackbox. Or rather I suppose, how to create the blackbox in the first place. Good to know the new vocab for it and this is a really good explanation, much better than I could give to new devs. I'd frankly send them to this video to learn the concept.

    @ShykinArcana@ShykinArcana Жыл бұрын
    • The way I understood it, monads require a logging of sorts no? Or was that just one use case for monad patterns

      @denisg1208@denisg1208 Жыл бұрын
    • Nevermind it was just an example.

      @denisg1208@denisg1208 Жыл бұрын
    • You've got no idea what you're saying and just saying things lol

      @user-tx4wj7qk4t@user-tx4wj7qk4tАй бұрын
  • Hey, this is great! You've got a good way of explaining things using plain English and building concepts from a basic level.

    @JamesWalker-rs1ps@JamesWalker-rs1ps Жыл бұрын
  • I recently discovered Effect-ts and was struggling to understand the basic concepts of it. The docs don't mention mondas while explaining how the library works (due to a valid reason. Mentioning monads scares people!) But this video explains it beautifully! Thank you man! You got yourself a subscriber 😊

    @mabuelhagag@mabuelhagag9 ай бұрын
  • Definitely lives up to the title, thank you for making such a great explanation.

    @prince_of_devils@prince_of_devils Жыл бұрын
  • This video is a true triumph. Thanks so much for making it!

    @MadaxeMunkeee@MadaxeMunkeee Жыл бұрын
  • I mean, "Its just a monoid in the category of endofunctors. What's the problem?" Scott Wlaschin also does a great job of explaining monads graphically with his "Railway Oriented Programming" talks. But this was a great "part to whole" way to take a single use case and expand the concepts, step by step. Nicely done!

    @dcuccia@dcuccia7 ай бұрын
  • I founded Vancouver's Functional Meetup which ran for 3 years...and we discussed monads a lot!! I had a lot of ongoing questions. I saw many presentations, yet I was always left wondering / wishing someone could actually show me a 'monad' rather than discussing the apparent philosophy or upper purpose! Finally, someone explained it with great code examples, which I could easily relate to Swift (my language) and completely and finally understand monads...I had assumed one didn't really need to know 'monads' to use them, and it turns out with arrays, maps/flatmaps, optionals, and even a plug in Then promise library - all these were monads of course and I didn't need to know one to use one...but your explanation nails it! Many thanks!!

    @julestburt@julestburt Жыл бұрын
  • Among all the functional programming videos in my feed this is the first one I understand something. Great video!

    @yeong126@yeong126 Жыл бұрын
  • I only wish I could like the video as many times as I have watched it. What an incredible presentation and a simple explanation of such a feared topic. Thank you.

    @eliote.corleyii5792@eliote.corleyii5792 Жыл бұрын
  • Impressive explanation. Quickly provided useful information that gives me better understanding of techniques I already use as well as new ones to adopt.

    @atrowell@atrowell Жыл бұрын
  • This is the best video explaining monads, thank you for the great yet simple explanation 😊

    @karavind7814@karavind7814 Жыл бұрын
  • Practical samples and very good explanations! Thank's for publishing!

    @hansschenker@hansschenker Жыл бұрын
  • I think a large part of the issue explaining Monads is the concept is actually so simple that there is a "why the special name?" question that makes people think it _must_ be more complex. It is a basic function-application pattern, the likes of which you learn the first time you write an async event loop, or implement a DSL-FSM (See Greenspun's 10th rule). And yes, just like the y-combinator, or lambda calculus, it has a basis and explaination in math that makes it look more complex than it really is.

    @yellingintothewind@yellingintothewind7 ай бұрын
    • None of what you said is true

      @user-tx4wj7qk4t@user-tx4wj7qk4tАй бұрын
    • In Javascript Promises/Futures are an example of a Monad, and in that case then is flatMap/ >>=. However, Monads generalize the idea of promises/futures to be able to embed any language with any sort-of semantics into the language, so promises/futures are a way of embedding asynchronous computing into a stateful language and have it look like synchronous code just like monads are used to embed imperative/stateful languages into purely function Haskell. The thing about monads is that you have to know their 5 other definitions and many other examples to see how monads can shorten your code by. You have to know Monads other definition like flatMappables containers where flattenable containers are called Monoids, Mappables are called Functors.

      @aoeu256@aoeu256Ай бұрын
  • wow, first time I know monad so clearly. thanks and looking for future video like this. really good video.

    @sgwong513@sgwong513 Жыл бұрын
  • Incredible video. I felt a lot of clicks, and feel like I may have understood monads better than I thought. Thank you!

    @TheJonBrant@TheJonBrant Жыл бұрын
  • Thank you so much for such a simple but relevant explanation!

    @aryanrahman3212@aryanrahman3212 Жыл бұрын
  • Great explanation. I'm going to use this as a benchmark when I do actual education videos.

    @ZackFreedman@ZackFreedman Жыл бұрын
    • yeah, now that i think about it the oscilloscope video was quite similar to this one

      @crckrbrrs@crckrbrrs7 ай бұрын
  • Absolutely greatly presented and explained, well done.

    @ocnah@ocnah Жыл бұрын
  • This is an amazing intro in the sense that the title isn't even a clickbait! ;) Thanks for the video!

    @tqian86@tqian86 Жыл бұрын
  • This is the first video that 'shows' the thing by including 'how to' aspect. Best video I came across so far.

    @rajthewise@rajthewise Жыл бұрын
  • You have quite a gift for education. Thanks for taking time to explain this.

    @wcarmon1209@wcarmon1209 Жыл бұрын
  • Best video i have seen on this topic. Most videos start with explaining monads, monoids, and endofunctors and are completely overcomplicated. Starting with an easy to grasp example is way better

    @d0m186@d0m1869 күн бұрын
  • I watched a few videos but this is the one that made sense to me. Thank you!

    @jn-iy3pz@jn-iy3pz Жыл бұрын
  • One thing I’ve noticed that is tricky is when you have a value wrapped in several monads. For example, if you have a value that is asynchronous and also can fail with an error. Then you have a value wrapped in a Future/Promise/Task as well as an Either. Would love a video about how to deal with this complexity. How to traverse between different monad lands.

    @dawid_dahl@dawid_dahl Жыл бұрын
    • You’d probably pass one “runWithLogs()” into another, nesting the functions in the same way the types are nested

      @Holobrine@Holobrine7 ай бұрын
    • Yep, because Promise.then() has the same type signature and meaning as flatMap (or bind in monad). It transforms promise, using a function transforming wrapped value into a new promise.

      @ivanjermakov@ivanjermakov7 ай бұрын
    • ​@@ivanjermakov wouldn't this be trivially solved by back-tracking the function through the unwrap, since both monads are Generic in their implementation? If you have a Future, what you probably have is something in the form of future(optional(5)), which can also be expressed as a chain operation as: let result: Promise = createOptional(5) | .createFuture($0) in which case you should probably be able to do something like `result.value.value` which should resolve without much problem: Unfulfilled promise would nil .none in the optional would also nil

      @HolyAvgr@HolyAvgr7 ай бұрын
    • Keywords are: monad transformers (more popular, safer to start with this) and extensible-effects (imho cooler) 😄

      @ArturCzajka@ArturCzajka7 ай бұрын
  • Very interesting and new to me. One small thing; what you call a caret, < or >, is more properly known as an angle bracket when it is used as a delimiter. This is a caret: ^.

    @CartoType@CartoType Жыл бұрын
    • Yes, worst part(s) of the video, that.

      @NicholasShanks@NicholasShanks Жыл бұрын
    • Exactly! So painful to hear every time. en.m.wikipedia.org/wiki/List_of_typographical_symbols_and_punctuation_marks

      @jasonzuvela@jasonzuvela Жыл бұрын
    • That's a circumflex.

      @31redorange08@31redorange08 Жыл бұрын
  • Thanks for putting this together. Obviously took some time and it is a dry topic. Much appreciated. 👍

    @n4vyblueyes377@n4vyblueyes377 Жыл бұрын
  • At last! Great video thank you so much!Great namings, wrapper instead of unit and run instead of flatmap or bind to explain the concept before the terminology. Please make more videos like this

    @aysubetin-can6435@aysubetin-can64352 ай бұрын
  • really well explained. I subscribed in the middle of the video, keep it up!

    @darkarie@darkarie Жыл бұрын
  • Alex you are the champion of the web. You deserve a noble prize for making these great videos.

    @abdulhamidalsalman@abdulhamidalsalman2 жыл бұрын
  • I'm not sure how I stumbled on to here but I'm glad I did. This is not only helpful as a software engineer, but a really good example of how to teach an abstract concept in a very accessible way. Very nicely done, and subbed!

    @SteveDellaValentina@SteveDellaValentina Жыл бұрын
  • You got me, I was about to freak out about you not mentioning Lists/Arrays. Very good explanation and examples!

    @atalhlla@atalhlla Жыл бұрын
  • I first grasped monads by thinking of them as piggybanks. The ceramic ones that you have to break. This perfectly compliments that, thank you!

    @endermannull4420@endermannull4420Күн бұрын
  • Stellar presentation of monads! Thank you so much!

    @ohm62@ohm622 ай бұрын
  • I kept seeing this video recommended to me, but I avoided it everytime thinking "this is gonna be too complicated, I'll watch it later when I have the time/energy." Glad I finally bit the bullet and watched it... was not disappointed. Fantastic explanation... please keep making videos like this!

    @atanugayen3030@atanugayen30306 ай бұрын
  • I watched a bunch of talks about what monads were, but this was the first to make me realize that I actually wrote one unintentionally last year while trying to learn about design patterns

    @Daniel_WR_Hart@Daniel_WR_Hart Жыл бұрын
  • I just made a monad this week without even realizing it, but I never thought about implement logging into it. I'll need to do that immediately because that would be extremely useful!

    @ryannygard3661@ryannygard36617 ай бұрын
  • 4:43 Thank you SO MUCH, seriously! When you said that it instantly clicked. This genuinely helped me so much, thank you!

    @kellybmackenzie@kellybmackenzie Жыл бұрын
  • Topo keep up the amazing work, you deserve more views!

    @Seyunx@Seyunx Жыл бұрын
  • Great explanation! Would love to see free monads as I'm struggling with those myself.

    @sergeiknyazev5564@sergeiknyazev55642 жыл бұрын
  • I’ve been struggling with the concept and think this may be the best presentation I have seen.

    @gavintillman1884@gavintillman18845 ай бұрын
  • can confirm, is the best introduction!! Honestly so so good

    @brettwines6812@brettwines68122 жыл бұрын
  • Great to see the clear examples in TypeScript!

    @avi3681@avi3681 Жыл бұрын
  • The fact that Swift has built in operator support for optionals using ? is so nice. It’s nice to be able to wrap up this behavior into a simple type declaration like User? (equivalent to Optional).

    @OroborOSX11@OroborOSX11 Жыл бұрын
    • dart as well

      @yahyaadinugraha1058@yahyaadinugraha10586 ай бұрын
    • It's not equivalent

      @user-tx4wj7qk4t@user-tx4wj7qk4tАй бұрын
  • Best explanation of monads that I have seen. Bravo!

    @grkuntzmd@grkuntzmd Жыл бұрын
  • Dude your channel is a gold mine!!

    @Daspem25@Daspem25 Жыл бұрын
  • This was extremely helpful, thank you!

    @Irokesengranate@Irokesengranate Жыл бұрын
  • I had never really studied monads, mostly because of "that stupid quote" - you know the one I mean. Then, I can't remember why now, I was looking at a promise one day and thought "could this be a monad?" I'm now looking for a way to explain to bosses why async/await isn't necessarily a good idea and why promises are actually much clearer. But bosses often want a "clever" explanation that's hard to understand so I've been thinking about invoking monads in my overcomplicated explanation... and here we come full circle because "deliberately overcomplicated" and "that stupid quote" are the very best of friends.

    @edgeeffect@edgeeffect7 ай бұрын
  • This is actually great teaching material, thank you so much!

    @Aucacoyan@Aucacoyan8 ай бұрын
  • Outstanding work! thank you so much.

    @eltongarcia6105@eltongarcia61057 ай бұрын
  • Big fat subscribe for this, made it so clear and gave great examples; thank you Alex

    @quinn_m@quinn_m Жыл бұрын
  • One of the best descriptions of monad!

    @kingshukmajumder2087@kingshukmajumder2087 Жыл бұрын
  • Thank you for this extensive explanation! 👍It's really useful as a background knowledge behind a ton of things in Rust that I learned, also because I have seen many people already talking about it there. Now I really understand it. 👏 But even in C#, a language in which I have worked for about 20 years now, I can relate several examples of monads as well. A nice one are so called LINQ functions, for example SelectMany, which is basically the literal equivalent of your FlatMap example. LINQ is the name of the most important functional programming API in C# and DotNet. Maybe it is also a good to mention that C# was really one of the first with the async await programming model, and it might even be the absolute first one. Though what you mentioned as Future or Promise are not the terms how they are used in C#, but what is used is generally Task or ValueTask, although other types can also be used sometimes.

    @jongeduard@jongeduard7 ай бұрын
  • Thanks for making such videos, they are helping me understanding code more. Will you ever come back online to roblox or make a new Clockwork Calculator? Do you still work at Blizzard?

    @SetUser@SetUser2 жыл бұрын
  • Dang. Within only 15 minutes you easily achieved what my professor in functional programming couldn't in an entire semester of 15 weeks lol. No seriously, this video has to be the best explanation for Monads one can find on KZhead!

    @nicolaus8622@nicolaus8622 Жыл бұрын
  • best monads explanation i've ever seen !, thank you !!!

    @ya3rub101@ya3rub101Ай бұрын
  • This is great! Can I ask what you use to create these beautiful slides with animations, equations and code?

    @korigamik@korigamik Жыл бұрын
  • this is the best explanation of monads I've ever seen, thanks

    @Sahuagin@Sahuagin7 ай бұрын
  • 13:30 It's called flatMap not only for lists, but for any type that introduces structure. More generally, it's called bind or concatMap, it has a type signature of (struct: Struct, transform: (value: T) => Struct) => Struct, and means "Map a function over structure and concatenate the resulting structures". It is possible, because any monad must also be a monoid: define how to combine structures. Basically, monad is a very general interface for flatMap.

    @ivanjermakov@ivanjermakov7 ай бұрын
  • great explanation. I will definitely use monads in my projects.

    @danilmartyniuk@danilmartyniuk6 ай бұрын
  • 0:30 thanks a lot for using appropriate font size - readable at 360p. it's such a small thing but makes such a huge impact on viewing experience.

    @yash1152@yash1152 Жыл бұрын
  • Very nice explanation, and easy to understand. I would just have added that `run` is sometime named `transform` or `map` in other programming languages. That being said, I thought that what you describe is a monadic interface, while modad was the abstraction over those interface. If you can write a modad, you have the same function that take either `Option` or `List` if instead of "stuff may be missing" you want "you may have zero, one or more element". For example Rust has multiple monadic interfaces (`Option`, `Result`, the try operator, `Iterators`, …) but no way to abstract over those so it lack the expressiveness to write a modad. Am I right?

    @robinmoussu@robinmoussu Жыл бұрын
  • Great video! One small correction, though: For the Option run method, you list that it only has one generic parameter. This implies the input type of the transform function must be the same generic type of the transformation's returned property. That's not true, since the getPet transformation transforms a User to an Option.

    @lukeb8349@lukeb8349 Жыл бұрын
  • very helpful. Perhaps the only place that gave me a better grasp of monads

    @jeffg4686@jeffg4686 Жыл бұрын
  • very well put together explanation 👏

    @semplar2007@semplar20078 ай бұрын
  • Just for reference, in C# flatMap for lists (actually, all collections that provide IEnumerble interface) is SelectMany in Linq. Future/Promise is the Task. One more interesting thing - async/await (combined with Task) is very close by it’s behavior and purpose to IO monad (not mentioned here) - it “infects” function so you need to make functions that call it async (or, at least, return Task) as well. And it brings a big mindset shift, starts building understanding that we want to keep “IO monad” part as small as possible, splitting logic and IO. It will allow to write most of tests without mocks at all. And the rest that works with “outer world” (db, user input, other services calls etc) better to test with real interaction, e.g. integration tests.

    @denys-p@denys-p Жыл бұрын
    • The second part you wrote is potentially a good point, but I'm not convinced it's true. I know exactly what you mean by "infection" (I call it "prionic", and if someone doesn't know what a prion is, I go for ice-9 if they've ever read Vonnegut). But, I'm not sure it's really possible to have async in any kind of way where it doesn't "infect" all of its uppers. Actually, callbacks in JS would possibly do this. But that's more a matter of using global state. Although, additionally, mutex's in general work this way. Thinking of reentrance patterns and such. Ok, you've convinced me. Yea I think this is a unique quality for Task. Even deeper, I think this may be a unique quality for Monads, overall. An accessory requirement for that to be the case is BTW this is somewhat similar to the mathematical concept of "absorbing elements". I think Undefined, though, would most-closely mimic the concept of a synthetic (ie intentional union with) construction of a category with an absorbing element.

      @MrRedstonefreedom@MrRedstonefreedom Жыл бұрын
    • **An accessory requirement for that to be the case MIGHT be that it's a typed language. Though I think that's just a straight matter of "in order to be less immediately annoyed of categorically wrong implementations"

      @MrRedstonefreedom@MrRedstonefreedom Жыл бұрын
    • @@MrRedstonefreedom Typescript (in the video) gets compiled into normal Javascript, mostly by stripping away the types. So the async/Promise stuff usually becomes the exact same operations in Javascript. For that matter, the node.js runtime has a utility function util.promisify() that converts a callback-using function into a Promise-using functions, and Promises have .then, .catch, .finally etc that resolve Promises with callbacks. The two are essentially equivalent.

      @KaiHenningsen@KaiHenningsen5 ай бұрын
    • A fellow c# bro.

      @C00l-Game-Dev@C00l-Game-Dev3 ай бұрын
  • Truly incredible job.

    @KennethBoneth@KennethBoneth2 жыл бұрын
  • Awesome! Keep it coming!

    @Ma1ne2@Ma1ne2 Жыл бұрын
  • Amazing explanation, thanks !

    @o__sama@o__sama7 ай бұрын
  • Dude… years… years I tell you!!!! Why does everyone else suck sooooo bad at explaining this! Finally! I feel complete. Ty

    @_blank_3677@_blank_3677 Жыл бұрын
  • This is a marvel of clarity.

    @jamesmstern@jamesmstern7 ай бұрын
  • I guess it's really as simple as that huh. I always heard monads are the bane of one's existence, but this seems rather beautiful and understandable. Grat video!

    @Goras147@Goras1477 ай бұрын
  • Thanks for the brilliant video!

    @camilosibarita@camilosibarita9 ай бұрын
  • Now we need a video, where we have side by side implementation of monads in Haskell and TypeScript

    @kirillnovik8661@kirillnovik86617 ай бұрын
  • Simply simple explanation sire !

    @Mrhennayo@Mrhennayo7 ай бұрын
  • Excellent delivery of information

    @Radioguy00@Radioguy00 Жыл бұрын
  • That was great! Much appreciated

    @IroXtreme@IroXtreme Жыл бұрын
  • Excellent explanation! Subscribed.

    @dawid_dahl@dawid_dahl Жыл бұрын
  • Hey Alex, thanks for this video. I'm sending it to all my software engineer friends who have heard of Monads but have no interest in figuring out if its actually a good idea.

    @hermaeusmora749@hermaeusmora7496 ай бұрын
KZhead