What is a monad? (Design Pattern)
Вставка
- Опубліковано 25 чер 2022
- Programming often relies on combining functions in data pipelines. The monad is a design pattern which makes pipelines with effect much easier to write and maintain.
Monads are often explained using haskell in complicated ways but I tried here to simply explain the pattern with javascript to build an intuition of them. - Наука та технологія
Hiya! It turns out that what is described in this video is the Functor and not the Monad. The difference between these two is quite minor so I'll leave it here.
A monad is just a functor which has some extra property within the bind method. Functions being passed in bind calls must have as their return types an instance of the monad being used. The bind method of a monad would then need to "unwrap" that value.
Wait, so I’m using a monad everytime I call .unwrap() in Rust?
@@wanderingthewastes6159 I would need to look into it but from the little I know, unwrap is a method of an Option type, which I believe is a monad. You would need to ask someone who knows more about rust than me, I've only seen like 2-3 No Boilerplate videos.
Hey can you do a full Video about Design patterns ?
No, no, no! What you described here *are* properties of a typical _monad_ (barring some technicalities).
_Functors_ are things you can write a _map_ function for, such as _lists_ (applies the function to every element inside), but also _maybe_ (apply the function if there is something inside).
a monad is just a monoid in the category of endofunctors
A monad is just a monoid in the category of endofunctors. I don't know what people don't get about that.
Hehe... Just wait a few weeks and I'll have a full video about that sentence (and all the CT necessary to understand it)
Yes. That is thing I understand.. endofunkting easy! 😁
"bart, say the line!"
@@Brunoenribeiro im tempted to ask stemg for his permission to use that clip in a video lmao
@@AByteofCode Subscribed to wait for it lol
I'm a big fan of the "fireship style" of videos and it's great to see more people creating high quality content like this
It's about time the style leaves web development and talks about other stuff :)
@@AByteofCode exactly
why is that in quotes lol
@@4xmo because he's not the creator
This channel is much better at this "style" than fireship, this one is much clearer, fireship's vids are a mess
I already know what a monad is: it's that thing that my annoying friend who's just learned Haskell won't stop talking about
Sounds about right :)
This 2 minute video is a better explanation of monads than some hour long lecture I've watched. Really good stuff!
Thanks for the kind words! Honestly those lectures are good but too long to focus on so they end up not being good. Lectures are also generally performed in front of a group of students with assumed knowledge basics. I wrote this video with no pre-requisites other than knowing a tiny bit of programming.
You may be very small now, but with this quality of content you will definitely be big one day!
Thanks for the kind words and optimism!
i approve this comment.
I approve this sentiment. The video content is high quality already and I support such efforts much. I can't wait to see what is next from "A Byte of Code", especially as a hobby programmer interested much in both past and future tech advances.
@@hydralisk98 Ever heard of JSF*ck? :p
@@AByteofCode You mean the JS implementation of Brainf*ck? Not the JS edition before this video but yes I am aware of it. I do am aware of much as far as my curiosity lead me to, both in esoteric prog langs and more serious ones like Common Lisp, C# and even exploring F#/F*. Hopefully as I dive into the history of web tech (going before even SGML & IBM's GML), we may collaborate on advanced programming functional structures soon. ^*^//
Fireship's influence shows. You're also just as talented at explaining complex things in a short time.
I started this channel in part to further the Fireship style to other realms of programming, so that is actually a great compliment, thank you!
And it's a great style. Imitating it, I think, will only bring good things as it mutates through creators picking it up.
Also, refreshing to see this style without the usual inside jokes fireship includes in his fast-pace videos which can sometimes be misconstrued as facts...
@@DavidSimonTetruashvili I agree fireship has an amazing way of showcasing content and that its a good place to start out from and develop one's own style off of it. Was expecting to have more time to adapt but youtube's algorithm did not agree. I watch a lot of fireship but can't think of any of these inside jokes off the top of my head, would you have an example or two by any chance?
@@DavidSimonTetruashvili I was thinking the same thing. It'll be very interesting watching this style evolve.
@@AByteofCode he usually uses irony! stuff along the lines (off the top of my head, not exact quote) of: "we all love getting a new framework every month"
What can I do to make my future videos better? Any feedback (even negative) is much appreciated!
remember to pin your comments so i can see then at the top :)
@@briandublidi4708 oh right yeah lol ty for pointing that out
This has to be the best explanation of Monads I have found out of all the many, many, many videos I have watched, and definitely the most productive 2 minutes and 30 second - highly recommended.
I suspect one of the major difficulties with explaining the concept are the different mindsets of the audience from the instructor. The vast majority of instructors will be from a declarative/Functional Programming background where solutions are defined in terms of what needs to be done. The audience will largely comprise developers from an imperative OOP/Procedural background where solutions are formed by defining the steps required to resolve the problem.
Having an explanation in terms of how the monad resolves a problem by absorbing some of the steps is really easy to understand. The last 60 seconds of this video really hits that message home, but I would not go as far as to suggest watching the video in reverse.
Thank you!! The second paragraph is definitively key to what made this video work. When I made it, my understanding of functional programming was pretty mediocre, making it no more than an imperative programmer trying to explain monads to other imperative programmers. However I never actually realized what I had done until this comment, so thanks for pointing it out :)
Not only it doesn't solve the presented problem, it's NOT a monad at all. Your lengthy comment is just silly.
I commend you for having so clearly and accessibly explained a notoriously difficult topic. I finally feel like I actually understand what these are now. Thanks!
Ayo glad to help!
These videos are well made, keep making them!
Glad you like them, I definitively will continue!
To the point, concise and clear explanation. Just what a developer needs.
That’s probably the best concise explanation of monad I’ve read so far!
I'm happy to hear that!
Great video±! You have enlightened my vision on computer science by finally explaining to me what a monad is dude.
lmao
There have been many attempts to explain monads and many have failed but your example makes it extremely clear, thank you
I'm happy to help :)
This is the most comprehensible explanation of monads I've come across. Thanks.
That is very nice to hear :) You're welcome!
The best Monad explanation I've seen so far.
Glad to hear that!!!
Most clear and concise explanation of monads that I've seen - amazing stuff
This is the most clear and intuitive explanation of monad I ever had. Thanks
Whoa, sifted through a lot of Haskell literature and was none the wiser. Thanks for the succinct explanation.
Glad it was helpful!
The best explanation I've seen so far, yet by far the shortest too. Great work!
Best explaining Monad ever.
:) Thanks for the kind words!
Finally understood why I would want a monad
You are an excellent instructor. I will stick with you.
Thank you!
Wow, that was a very clear explanation !
Now I know how useful monads are.
Unfortunately, I already forgot what they are.
After watching this video again after months and others of countless explanations + category theory, I think I'm finally beginning to get it
Glad to hear that!
In 2 minutes you explain concept that everyone else can't explain in 20 minutes or more!
Insane quality of content for a channel so small. You've earned my subscription
Thank you! I'm glad you enjoyed this video that was uploaded to a 30 sub channel :)
Thank you. I still don't understand monads, but this is the very first video which gives me hope that I might understand monads one day.
You can do it :)
Being a functor or a monad doesn't matter you've done a brilliant video in a beautiful way that would hopefully inspire newer developers to be better, respect to you
Reading this gives me the happy :) Thank you for the kind words!
I am glad that I found this channel, I love to learn something new like algorithms and complex information rather than seeing basic stuff and useless tutorials,. Keep it up man
Thanks for the kind words :)
After years of visiting this topic, I finally get it. Thanks!
Glad it helped! :)
This is so incredible. So simple understandable and clear. Well done!!
Thanks for the kind words :)
Very good video; all killer, no filler.
Hehe that's the goal! Thanks for the kind words :)
This is the first explanation I've heard that makes sense.
:)
This is best explanation ever I got about Monad or Functor for that matter!
Thanks for the kind words!
Very short and sweet explanation! I like how you explained concisely the reason to use monads and how they basically work
Glad it was helpful!
God-tier explanation, extremely concise and easy to understand.
Thank you!
Thanks for the kind words!!
I still don't understand monads 100%,
But this video is where I can say I got the closest to understand them.
And the most surprising thing is the video length! I have watched, before this, a lot of other videos about monads, and some of them were really long and thorough, but I consider this one is the best so far.
I can't be sure whether it's the example you gave or the fact that I'm watching this after watching many similar videos, but this is defiantly QUALITY CONTENT, short, concise, holistic and well-narrate.
Thankyou very much
This brings a smile to my face :) If you don't plan on going into functional programming, just think of monads as a smart box that does stuff to its contents for you. (Its more than that but the distinction doesn't matter outside of FP)
@@AByteofCode tnx!, yup I think the smart box analogy do it for me now
@@sharbelokzan9673 Ayy that's good to hear! Was considering using that analogy for the video itself but decided to avoid using metaphors
Yeah this is the most concise explanation of a monad I've seen and in a way that a regular programmer would understand.
@@AByteofCode Question for you.
I see the Maybe monad example in this video as a way of relocating many examples of a problematic procedural step ("procedural" in the normal English sense) down to a single isolated location.
As a result, common problems stemming from that step (in this case, problems with function calls and property accessors) can be handled in common.
I have an example which I think fits this pattern, and therefore might be a monad.
Is there a term for a monad which relocates side effects, like state updates/assignment or DOM renders, in much the same way that you relocate function calls and property accessors?
I love you. I was referred to a 12 mins video about monads, I watched all of it and I swear I had no idea what it was talking about. I got the clear idea of what monads are in 2 short minutes.
Glad to hear that!
Not even 3 minutes, straight to the point and had me saying "oooohhhhh, no f*cking way it was this simple" at the end. 10/10 video
Thanks for the kind words!
Short and sweet. Very well explained. Thank you!
:D
your content is fresh and I don't see this type of content anywhere else, subbed!
Thanks for the kind words and the sub! I'll try my best to keep the content going :)
You're a gem, my friend. Keep up the great work!
Thanks for the kind words!
Very cool, much impressed! Glad to have found your channel.
Thank you! I'm also glad you found my channel :)
Wow, I have been developing for 7 years, and I did not know about this, very cool!
Learn something every day!
I absolutely love that your video is very readable. A lot of content creators make content that's unwatchable unless you're a freakin' eagle.
The benefit of spending a whole month on a single video :)
Hands down the best explanation of Monads I have seen on youtube.
Ty for the kind words!
@@AByteofCode my pleasure!
I love how monads are explained with such example that fights JS absurdity
what is wrong with JS? In fact, it is in JS that this problem can be solved with using optional chaining which keep the code readable and debuggable at the same time.
@@hello-world1 chaining is doable in every language that supports OOP. And don't get me started with JS wrongs...
@@sunofabeach9424 not chaining, optional chaining meaning that if you put .. then the program won't throw if the prop can't be accessed. ok get started let's hear.
@@hello-world1 ah, I checked what this "?." does. The one thing it can do is just short-circ evaluation. While it is useful at times, it does not let you bind a callback function or manipulate the object this callback is attached to. It is not nearly as powerful as a monad.
It's funny that this "?." serves one purpose - to make null-checks more compact, while nulls shouldn't be a thing in the first place
this video is so good that im pissed. this concept is literally so simple and yet all the "explanations" existing online are like "hey buddy youre gonna need a computer philosophy degree for this" and then explain nothing. but like this + your clarifying comment make crystal clear sense. im so pissed. great work
Thank you!! The way I see it, monads are SO simple that the phd nerds think that if you don't understand, you're an idiot and so they use complicated examples. Another common pitfall is the whole "explain it in haskell" thing, where if you can understand haskell, you probably know monads already.
Finallyyy i understood it, computerphile video was complicated for me, your small example was really easy to understand
The computerphile video was the first one I saw while researching the topic. I'm gonna go rewatch it see if it makes more sense now. It's a shame that video appears first under the search term monad when all it does is complicate things
Devastating synthesis, straight to the point. Subscribed.
Hearing that gives me the happy :)
This is awesome! Thank you for this easy-to-understand video
Glad you enjoyed it! You're very welcome!
This is awesome! Thank you for the explanation!
Glad it was helpful!
So much info in ~3 minutes, great 🔥
Eyyyy :D
This is the best explanation I have ever heard thank you
Your welcome and thanks for the kind words!
Great video. Easy to follow with beautiful graphics. Thanks. :)
Thanks for the kind words :) Glad you enjoyed!
That video is awesome, congrats for the great content!
Thank you for the kind words!
Now yes, a decent quality video. Keep up the good work man!
Thanks, will do!
Easy, to the point explanation, subbed, looking forward to new videos!
Ay thanks! Any specific topics you'd be interested in?
So excited to see what comes next with ur channel, keep up the great work :)
What an interesting coincidence, I'm also excited to see what comes next!
Actually the most understandable explanation and nearly the fastest, didn't expect that from such small channel, keep it up)
Fun fact I had 30 subs when I posted that video :) Thanks for the kind words, I'll definitively keep it up!
strong, powerful, simple, great video
Thank you!
Good Job. You're on the rise!
Yeah its pretty insane. Thanks!
This is interesting first time hearing about monad, pretty interesting to try
Good luck with that! I'm glad I saved someone from spending 12 hours watching random youtube videos trying to understand lol
Wow, such a short video but better than the 10 to 14 minute videos I've watched. Well done.
Thank you!
honestly pretty cool and well explained
This is lovely. Looking forward to seeing more from you. Subbed!
Thank you!
Great explanation, thanks!
Thank you for the kind words :)
Such a good explanation. Thanks!
You're very welcome! I'm glad I was able to help!
Wow the quality of this content is just unbelievable, keep it going
That is music to my ears! Thanks for the kind words!
Amazing content. Will share this with my NL audience. I'm sure you will blow up
Thank you my man!
That's some quality content!
I'm glad to hear that :) Ty!
I've spent a few hours reading Mark Seemann's blog to first understand the concept, turns out I could have just watched a 3 minute youtube video instead 😂 Excellent
:D
Pretty great explanation. Thanks. Would love the video to be longer with more examples.
Thank you!! I have a monad video planned about the category theory definition and a massive functional programming one which'll mention a multitude of monads. But considering the success of the topic, I could definitively see myself make a dedicated video about a ton of different monad types.
Really good explanation for a 2:30 minutes video!
Glad to hear that! (Or is it a good explanation _because_ its 2:30 long and thus without bloat?)
Such a simple and precise explanation... wow, 100% immediate sub, please keep up the nice work!
Will do! Glad you enjoyed :)
first channel that i subscried after only wathing one video . Amazing content.
Ayyyy glad to hear that and thanks for the kind words!
You earned yourself a follow!
thanks, this was really helpful!
Holy crap, this is super useful and a way of thinking that I haven’t thought of before. Nice work!
Glad I could be helpful! Thanks for the kind words :)
This is the best explanation ever
Aww thank you!
I studied haskell during my computer science degree, but this is the first time I've actually understood what a monad is.
I like it, direct to the concept
Another commenter said, "no filler, just killer" and that is a good description of what I strive for :)
Nicely explained!
Thank you!
Subscribed at 12.7k! See you at a million in just a bit.
Thanks for the kind words!
Finally an actual explanation of a monad.
The ironic thing is the video is technically inaccurate, it describes the Endofunctor. For it to be a Monad, the function passed into .bind would need to return an instance of the Monad in question. Although, if you're not a functional programmer, the difference doesn't really matter and since noone knows the nuance, you can still use endofunctors and claim it to be a monad :p
@@AByteofCode nah I really didn't know much about monads I'm just a simple webdev who makes games in part time
But that pattern looked much familiar to promises
@@thatsalot3577 Turns out Javascript promises ARE monads! They were designed like that I believe.
Excellent video!
Thank you!!!
Great explanation.
subbed for more design paterns + like and comment for the yt algo keep it up man
Thanks man! Any specific design pattern you'd like to hear about?
incredible content this is what the people need
:) Thanks for the kind words!
Good!! thanks for this content!
My pleasure!
This... Is pretty cool, thanks!
Brief yet informative and very well presented. Keep growing, friend, I've already contributed and I'm waiting for next videos :)
Thank you for the kind words!
Love that this video isnt a 2 second video saying "a monad is just a monoid in the category of endofunctors" and actually explains the concept in a practical way
I love that video "what is a monad" where its just a robot reading all the different dictionary definitions and none of them make any sense whatsoever (even talking about non programming uses of monad)
Great video!!
Thank you very much!
This video is more like a text book to teach how to make people subscribe in 2.5mins
Informative, clear, interactive expression
Instant subscribed
This comment is music to my ears! And considering the view to sub conversion rate I think you're right :)
I would prefer how F# or ML way to explain this as “function composition”, for chaining functions together in a correct types order like a factory.
Just that simple.
In Rust, it use Option so most of time you need to unwrap, but it also can help compose functions with “.” Operator. Which is very convenient and less confusing to people.
I think for OOP users, the dot operator would be quite confusing. There are many ways to explain and the idea of function composition is a pretty good alternative, I mean, I was thinking of using that for this video but thought the pipeline idea would be more intuitive for my target audience of OOP devs
@@AByteofCode would be great if you gather all those languages and compare them in doing this feature.
Fsharp, Ocaml, Haskell, Rust, Ruby, even JS … ha ha
@@thanatosor Hmm. Not sure what point we'd be trying to prove there. Monads, outside of complex stuff like Promises, aren't really suitable for anything OOP. I just used javascript in this video because my focus was on people just knowing what the word meant and using a language which actually uses monads would have added too much obscurity to be understandable
@@AByteofCode to my latest comment, it’s just my idea, since I tend to make the same thing in different languages.
Nothing more to prove I guess.
Not a big fan of JS but I admit that it’s everywhere now.
@@thanatosor Yeah I'm not a big fan of JS (python supremacy) just forced into using it by circumstance (and in videos because everyone knows it so nothing to explain). I guess it could be interesting to have a repertoire of what certain patterns look like in different languages, you're right.
Excellent video bro.
I didn't expect such quality from a ~350 sub channel
The sound got much better compared to older videos (I think you got a little bit more confident)
I'll make sure to share your channel with some of my friends to help you grow :)
Hehe and I had 30 subs when I posted that video :) Also thanks for the kind words and help, I appreciate it!
almost 3k subs in just 4 days, so yeah this channel is gonna blow up
@@proloycodes That would be a certified pog moment :) If my current growth rate continues for a week I'll be at 10k. In any case, I have a couple of videos planned out that I suspect might check the same boxes as monads do so that might be helpful too. As someone who was hoping for 100 subs by the end of the summer, all of this is absolutely insane!