A Monads Approach for Beginners, in Scala | Rock the JVM

  Рет қаралды 39,269

Rock the JVM

Rock the JVM

Күн бұрын

Пікірлер: 102
@politrons
@politrons 4 жыл бұрын
One of the best Monad laws I've ever seen. Very nice man!
@rockthejvm
@rockthejvm 4 жыл бұрын
Thanks!
@ketanpurohit9086
@ketanpurohit9086 3 жыл бұрын
I have read articles and books, cried tears of blood while going thru them. And then I find this.. Wow -- well done. If your courses are like this.. I am a buyer for sure. Keep up the excellent work.
@rockthejvm
@rockthejvm 3 жыл бұрын
Such awesome praise, thanks! I have lots of content like this on the site.
@rohanurkude8503
@rohanurkude8503 2 жыл бұрын
Bravo!!! There are no bad students , just incompetent teachers. I am proud to say I CAME ACROSS THE BEST TEACHER!!! Kudos to you Daniel :)
@rockthejvm
@rockthejvm 2 жыл бұрын
Such high praise, thanks!
@michaelreuter5403
@michaelreuter5403 4 жыл бұрын
Absolutely best description/explanation I have seen! It "clicked"
@rockthejvm
@rockthejvm 4 жыл бұрын
Great to hear!
@ernestbednarczyk5745
@ernestbednarczyk5745 4 жыл бұрын
You've got talent for keeping watcher's attention through whole 40min video :) Thanks for great content!
@rockthejvm
@rockthejvm 4 жыл бұрын
Thanks - glad it's useful!
@daqo98
@daqo98 2 жыл бұрын
Such a brilliant explanation. Thank you very much!
@sagnikbhattacharya1202
@sagnikbhattacharya1202 4 жыл бұрын
This video FINALLY made me understand HOW to use monads!
@rockthejvm
@rockthejvm 4 жыл бұрын
That's my goal!
@slim_mike
@slim_mike Жыл бұрын
I liked very much that you skipped the theory and stick to the behavior of the code, you can always read more about the theory if you want but explanations like this with demostration on the the terminal, I think is what is most valuable for this video. Keep up the good work! and thank you very much!
@ivanvelikanova9950
@ivanvelikanova9950 3 жыл бұрын
I am so happy I went through this video. 40 mins felt a bit too much, but I guess it was required to understand. Thanks a lot.
@rockthejvm
@rockthejvm 3 жыл бұрын
Glad it was useful!
@LucaSavoja
@LucaSavoja 4 жыл бұрын
Thanks Daniel, really appreciate, I'm studying Cats right now but this video was very clear and helpful!
@rmiliming
@rmiliming 2 жыл бұрын
Very clearly explained. The examples used are good for helping me understand the concept. Thank you very much!
@valcron-1000
@valcron-1000 4 жыл бұрын
Great video explaining a topic that often gets beginners confused. I would add that most developers have used monads in some way without knowing the underlying concept: - async/await especial syntax is kind of the same as 'for comprehension' but specialized for async code. Instead of using 'await' you use '
@rockthejvm
@rockthejvm 4 жыл бұрын
Well said!
@tungtranvan1286
@tungtranvan1286 3 жыл бұрын
The first time I watch the video, I still didn't understand Monads. But, in the second, I got it. Thank you!
@rockthejvm
@rockthejvm 3 жыл бұрын
Glad it clicked!
@2kawaii2care
@2kawaii2care 3 жыл бұрын
I really learned a lot from this vid! Thanks! I’m not a Scala dev but I think I can use that new flatMap approach when working with Stream API from Java 8!
@rockthejvm
@rockthejvm 3 жыл бұрын
Amazing, that's my goal for these videos - transferrable skills!
@sherwin96
@sherwin96 4 жыл бұрын
Was waiting for such a Video. I loved the explanation at the end for the monadic laws and it did help a lot by giving concrete examples. Something that can be added as an extra to your advanced scala course. Great Video as always !! :)
@rockthejvm
@rockthejvm 4 жыл бұрын
Glad you liked it!
@omkarkulkarni9202
@omkarkulkarni9202 3 жыл бұрын
Dude, you should really have some commercial videos made! You are the best :)
@rockthejvm
@rockthejvm 3 жыл бұрын
Thanks! Check out the Rock the JVM website, I have full-blown courses on a ton of stuff.
@dedpihter5870
@dedpihter5870 3 жыл бұрын
I've heard that Monad has one more property - anyone who got understanding Monad immediately looses ability to explain it to other people. You proved it's not true. Thank you for the fantastic Monad explanation!
@rockthejvm
@rockthejvm 3 жыл бұрын
Thanks!!
@paveltroev8221
@paveltroev8221 2 жыл бұрын
done lots of haskell a while back but never heard of the 'm-word', gonna embrace it :-)
@ebuzertahakanat
@ebuzertahakanat Жыл бұрын
14:21 you didn't mention not returning null which cause esoteric null pointer exceptions which is another benefit of option
@ggsgetafaf1167
@ggsgetafaf1167 Жыл бұрын
thank you, I read cats book, too hard to understand, but I got all after watching your video.
@cgmds1973
@cgmds1973 4 жыл бұрын
Thank you for the video, I really like the examples !
@seanhdr4k629
@seanhdr4k629 3 жыл бұрын
Thank you for this wonderful video as well. I always press 'like' button. From my understanding, I presume 'for-comprehension' for List(1,2,3) and List('a', 'b', 'c') would yield a cartesian product..
@rockthejvm
@rockthejvm 3 жыл бұрын
Thank you! Yes, that's true.
@VRMediaI
@VRMediaI 3 жыл бұрын
Excellent video, sad that so few people have seen it.
@mehow.
@mehow. 4 жыл бұрын
scala 'for' reminds me of do/return from haskell
@mourikogoro9709
@mourikogoro9709 4 жыл бұрын
(8:57) line 12-13 the function actually does synchronized twice, Is that necessary for the purpose?
@mourikogoro9709
@mourikogoro9709 4 жыл бұрын
Can I write this instead? def flatMap[S] (transformer: T => S): SafeValue[S] = { SafeValue(transformer(internalValue)) }
@rockthejvm
@rockthejvm 4 жыл бұрын
@@mourikogoro9709 there is no double locking in this example. What you're suggesting is a map function (not flatMap).
@mourikogoro9709
@mourikogoro9709 4 жыл бұрын
@@rockthejvm Am I really misunderstand? Why? 1st synchronized is during apply the function's argument (i.e. transformer: T => SafeValue[S]) 2nd is the synchronized block of the flatMap function itself
@rockthejvm
@rockthejvm 4 жыл бұрын
@@mourikogoro9709 the transformer argument is a function value which can be anything; it has nothing to do with the transform method of the previous SafeValue implementation
@biniamgebregergs4282
@biniamgebregergs4282 Жыл бұрын
Amazing video. Thanks a lot.
@dangalimov7435
@dangalimov7435 2 жыл бұрын
Really useful video!
@weissmannrob
@weissmannrob 2 жыл бұрын
Very well done 👍
@k.l7111
@k.l7111 3 жыл бұрын
At 31:02 you mentioned ‘Monad(x).flatMap(f) == f(x)’ , I am afraid this is not always right. If we try: ‘def createVector(x:Int) = Vector(x, x+1) ; List(3).flatMap(createVector) ‘ the result should be ‘List(3, 4)’ but according to your formula it would be ‘createVector(3, 4)’ i.e. ‘Vector(3, 4)’ The correct explanation can be ‘Monad(x).flatMap(f) == Monad(x).map(f).flatten’ which one can consider as ‘Monad( f(x).flatten )’ . Think of it as just flattening the inside structures. Hope this is helpful. Thank you for the great video.
@rockthejvm
@rockthejvm 3 жыл бұрын
You're mixing lists with vectors, which are obviously different things. Even so, the returned type is still a supertype of both, which still satisfies the law. The monad laws as I stated them in the video are still true for functions returning lists.
@colin398
@colin398 Жыл бұрын
Why flatMap which makes us transform the thing into a SafeValue again? Why not use map, so we dont have to write the "wrap" step in our transformation function?
@rockthejvm
@rockthejvm Жыл бұрын
flatMap is useful when all you have is functions returning SafeValues - if you simply map the transformations, you'll get a SafeValue[SafeValue[...]], which is not what you want
@colin398
@colin398 Жыл бұрын
@@rockthejvm Ohh okay, I was thinking maybe there was a way to avoid those nested Monads without using flatMap. But I guess not. Thanks for the awesome content
@ZoYaBoBo
@ZoYaBoBo 2 жыл бұрын
God explanation, thank you man now i understand that sh`t !!! You have really awesome teach skill !!!
@gastonfernandorosso4226
@gastonfernandorosso4226 2 жыл бұрын
Isn't the prop 2) a special case of prop 1) when f = x => Monad(x) ?
@d4devotion
@d4devotion 3 жыл бұрын
Sorry I forgot, why you keep on saying never use Double for money in app, can you please elaborate this ?
@rockthejvm
@rockthejvm 3 жыл бұрын
Doubles can't represent tens and hundredths with full precision, which means you can lose cents on every operation. Use decimals instead.
@d4devotion
@d4devotion 3 жыл бұрын
@@rockthejvm Is there any blog you have written around it ?
@SanjaySinghaniaIN
@SanjaySinghaniaIN 2 ай бұрын
Increment the font size please!
@dmitrydidi
@dmitrydidi 4 жыл бұрын
great explanation! thanks man!
@rockthejvm
@rockthejvm 4 жыл бұрын
Glad it helped!
@chriseteka
@chriseteka 4 жыл бұрын
Thank you for the video daniel.
@kaktusdono
@kaktusdono 3 жыл бұрын
I have an issue with the first monad rule, at least as it was described here. Is it correct to assume, that in the formula: ```Monad(x) .flatMap(f) == f(x)``` the function is not just a function, but a function that can returns a Monad of the same type, and can be described as ```f[T](x: T): Monad[T]``` Am I correct to assume that? I can see that it's true for lists, but I am not sure whether it's true in general terms. Because *Option(12).flatMap(_ * 2)* is not equal to 12 * 2, it is *Option(12 * 2)* UPD: same goes for the third rule. I guess we cannot just apply flatmap to the result of *f(x)* if it is not a monad itself.
@rockthejvm
@rockthejvm 3 жыл бұрын
Your counterexamples are improperly typed - you can't say Option(12).flatMap(_ * 2), but rather Option(12).flatMap(Some(_ * 2)), in which case the law holds. Same for the third law. It's not that you can assume f to be of type T => Monad[T], but you MUST assume that by the type signature of flatMap.
@kaktusdono
@kaktusdono 3 жыл бұрын
@@rockthejvm thank you!
@jamesking2172
@jamesking2172 4 жыл бұрын
Please do an explanation of tagless final 👍
@LucaSavoja
@LucaSavoja 4 жыл бұрын
oh that's would be great!
@kmac499
@kmac499 3 ай бұрын
Dear God, can someone anyone please just tell me what a monad is,,, i can describe a data type, a parameter, an array, a procedure, a function, an object, recursion construcrors etc by simple analogy....but monads always instantly descend into novel and hence impenetrable jargon,,,,
@LuizRobertoFreitas
@LuizRobertoFreitas 4 жыл бұрын
Monster!!! Thank u man
@rockthejvm
@rockthejvm 4 жыл бұрын
Glad it clicked!
@theanigos
@theanigos 4 жыл бұрын
Weekends are good learning scala.
@rockthejvm
@rockthejvm 4 жыл бұрын
I know, right? :D
@badwolf8112
@badwolf8112 4 жыл бұрын
thank you. p.s. would be nice if the text font size was extremely larger.
@rockthejvm
@rockthejvm 4 жыл бұрын
Got it - are you watching the videos on mobile?
@badwolf8112
@badwolf8112 4 жыл бұрын
@@rockthejvm no. im used to not having to go to fullscreen/look fairly close. "programming in mosh" on youtube usually has text size bigger than one would code with but I think it benefits not only mobile, but on pc is also window mode more readable than smaller font looks in fullscreen.
@Code4Life
@Code4Life 4 жыл бұрын
Can u upload more video about implicit ?
@Code4Life
@Code4Life 4 жыл бұрын
And some functional topic like fold, foldLeft and foldRight
@sherwin96
@sherwin96 4 жыл бұрын
He has a course on all of that on Udemy :)
@Code4Life
@Code4Life 4 жыл бұрын
@@sherwin96 I have learned that but feel not enough :# at advanced scala course :V
@sherwin96
@sherwin96 4 жыл бұрын
@@Code4Life if you haven't done the Coursera scala specialization,, that is something I would suggest you look into. It really dives deep when you talk about those functions. It also covers implicit's in its entirety. You won't get anything better, especially if you solve the assignments.
@jamesking2172
@jamesking2172 4 жыл бұрын
Love it 👍
@waagnermann
@waagnermann 4 жыл бұрын
At 30:22 you enumerate Option, Try, Future, List as Monads but Future actually is NOT a monad!!!
@rockthejvm
@rockthejvm 4 жыл бұрын
There's this age-old discussion whether a Future is a monad or not, since it includes the passage of time. For beginners (which is the scope of this video), we'll just consider Future to be a monad.
@vijayvaswani9717
@vijayvaswani9717 3 жыл бұрын
you are awesome..!
@DiegoFerreiradaSilva
@DiegoFerreiradaSilva 4 жыл бұрын
amazing video, thanks
@rockthejvm
@rockthejvm 4 жыл бұрын
Glad you liked it!
@sagojez
@sagojez 3 жыл бұрын
Is there a list of what types of variables are monads? List, Futures, Options.. but what else? BTW Great video!!
@rockthejvm
@rockthejvm 3 жыл бұрын
Lots of things are monads. Just remember the monad properties. Reader, Writer, Eval, State, IO are other examples of monads.
@sagojez
@sagojez 3 жыл бұрын
Thank you 😄
@AntiMyth
@AntiMyth 2 ай бұрын
The 127th video on monads that I still don't understand. I've understood every single description and example I've ever watched. Every one of them describes these behaviors and properties. Why though? You need to understand monads because....???
@ivanvelikanova9950
@ivanvelikanova9950 3 жыл бұрын
This is what I learned about Monads (1) Monad - has a pure constructor, and a flatMap (2) Monad(x).flatMap(f) == f(x) (3) Monad(v).flatMap(x => Monad(x)) == Monad(v) // Useless (4) Monad(v).flatMap(f).flatMap(g) == Monad(v).flatMap(x => f(x).flatMap(g)) I feel so outdated. I seem to have not touch maths for the last 12 years, and nothing other than Java, until a few months ago.
@oleksii9512
@oleksii9512 3 жыл бұрын
cool!
@Orangubara
@Orangubara 6 ай бұрын
After watching this video I feel like Neo disconnected from simulation when he said "I know kung-fu"
@donwald3436
@donwald3436 Жыл бұрын
Scala users still haven't switched to Kotlin?
@rockthejvm
@rockthejvm Жыл бұрын
Not until Kotlin has this sort of power
@francis.joseph
@francis.joseph 2 жыл бұрын
rocks
@anzo.p
@anzo.p 3 жыл бұрын
genious
@101graffhead
@101graffhead 3 жыл бұрын
>hey bro monads are easy just read an article or two, you will understand them >search monad on youtube >all videos are 30+ minutes h-haha functional programming is cool, oop suck amirite guizzz
@rockthejvm
@rockthejvm 3 жыл бұрын
All important questions in life take time to properly sink in.
@mohamadshaker4236
@mohamadshaker4236 2 жыл бұрын
The problem with monads is that once you know what is, you lose the ability to explain it
@ayyubayyyub9415
@ayyubayyyub9415 2 жыл бұрын
The color theme makes it hard and boring to follow, please change the theme to atom one dark theme.
@luisdominguesforprogramaca3221
@luisdominguesforprogramaca3221 2 жыл бұрын
WTF? Is this an explanation for beginners? Of what?
@rockthejvm
@rockthejvm 2 жыл бұрын
Still looks like rocket science?
@apolloartz_5372
@apolloartz_5372 6 ай бұрын
Really helpful video!
What the Functor? | Functors in Scala | Rock the JVM
24:43
Rock the JVM
Рет қаралды 12 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
How To Easily Do Asynchronous Programming With Asyncio In Python
23:09
The Flaws of Inheritance
10:01
CodeAesthetic
Рет қаралды 996 М.
Scala Generics: A Gentle Introduction
23:48
Rock the JVM
Рет қаралды 7 М.
Martin Odersky - Scala's Role in the Programming Languages Ecosystem
45:53
Scala Days Conferences
Рет қаралды 13 М.
Why is C# Evolving This Way?
15:02
Zoran Horvat
Рет қаралды 24 М.
The Absolute Best Intro to Monads For Software Engineers
15:12
Studying With Alex
Рет қаралды 680 М.
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 148 М.
The Future of Typelevel Concurrency by Michael Pilquist at Scala in the City
47:19
John A. De Goes at #ScalaUA - Thinking Functionally
51:36
ScalaUA Conference
Рет қаралды 19 М.
She made herself an ear of corn from his marmalade candies🌽🌽🌽
00:38
Valja & Maxim Family
Рет қаралды 18 МЛН