Тёмный
No video :(

Contravariance in Scala: Why Is It So Hard? | Rock the JVM 

Rock the JVM
Подписаться 23 тыс.
Просмотров 15 тыс.
50% 1

Written form to keep for later: blog.rockthejv...
This video is for the Scala programmer who's only been using generics in their basic form: either with collections, or simply attaching a type argument to a class/trait and minding their own business.
I will introduce the concepts of co- and contravariance and why they are useful, with a few examples and some rules of thumb to follow, without getting into the academic weeds that otherwise make these concepts seem so obscure and confusing to most programmers.
Follow Rock the JVM on:
/ rockthejvm
/ rockthejvm
-------------------------------------------------------------------------
Home: rockthejvm.com
-------------------------------------------------------------------------

Опубликовано:

 

22 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 60   
@sergeikharchikov1157
@sergeikharchikov1157 4 года назад
You definitely have a talent for explanation
@rockthejvm
@rockthejvm 4 года назад
Thank you1
@hinocenciopaulo
@hinocenciopaulo 4 месяца назад
Finally, someone could make me understand this thing... BTW I came here without any knowledge of Scala (my background is from Kotlin lol). The way that you explained it is so good that I could understand it even with examples in a language that I had never seeing before. Thank you so much.
@_mumbler_
@_mumbler_ 3 года назад
The best explanation of contravariance I’ve seen.
@rockthejvm
@rockthejvm 3 года назад
That's my goal, glad it helped!
@yohaitol
@yohaitol 3 года назад
I have read several explanations about the variances subject and never felt like I fully understood it. This video is the best explanation I found, now I feel very comfortable with it. Thanks a lot and please make more videos like this :-)
@rockthejvm
@rockthejvm 3 года назад
Brilliant, glad it clicked!
@awesomebearaudiobooks
@awesomebearaudiobooks Год назад
Taking my fedora off to honor the humanity-changing great feat of Laika the space dog 😔🎩 You will forever be in our hearts, comrade Laika ❤ Let's honor her memory by studying hard, so that the people of the world can finally tame the boundless nature of outer space... With the help of Scala, obviously.
@jimaaman
@jimaaman 3 года назад
Slowly coming to terms with this concept but the consumes vs. produces rule of thumb is the best summary I've seen so far of when to apply variance. 👍
@rockthejvm
@rockthejvm 3 года назад
Glad it clicked!
@colin398
@colin398 Год назад
I liked your examples a lot
@Alchimystic
@Alchimystic 8 месяцев назад
An interesting natural example where variance and contravariance exist, even if doesn't seem logical: human blood types. In terms of blood cell compatibility, O is the universal donor (provides for every other), while AB is the universal receiver. In terms of plasma is the other way around: AB is the universal donor, while O is the universal receiver
@rockthejvm
@rockthejvm 7 месяцев назад
Nice example!
@vetiarvind
@vetiarvind 2 года назад
wow, underrated channel, i remember drawing a lot of diagrams explaining contravariance in stackoverflow once so i thought i understood it but you have an incredibly effective way of distilling information. i'm going to watch all your videos just to see how you explain it ==)
@sergeykvartalnov8232
@sergeykvartalnov8232 Год назад
Best Scala tutorials evere, I'm so happy I found your channe. Perfect 💯
@flaviodasilveirapepino6076
@flaviodasilveirapepino6076 4 года назад
I've benn waiting for this video!
@UniformDelta00
@UniformDelta00 Год назад
What a wonderful video, this subject was so vague for me, thank you !
@welltv1142
@welltv1142 Год назад
That was really helpful, thanks man!
@mikepictor
@mikepictor Год назад
Really really good explanation. It feels quite intuitive now
2 года назад
This is the best explanation of this concept I have seen till now! Thanks, Daniel!
@MrCesarification
@MrCesarification Год назад
Wonderful stuff
@mourikogoro9709
@mourikogoro9709 3 года назад
A god-send video!
@rockthejvm
@rockthejvm 3 года назад
Glad to hear it's useful!
@OmarMendozaKS
@OmarMendozaKS Год назад
Awesome video man, quite simple, after some research I was almost at the starting point to understand this, your approach rocks, just one complaint, Hachi was not a lucky dog, he is a legend, 👏
@temoncher
@temoncher 2 года назад
The best co- vs contravariance explanation in the world
@rockthejvm
@rockthejvm 2 года назад
Thanks!
@TJ-hs1qm
@TJ-hs1qm 3 года назад
so awesomely explained I finally got it. Thank you!
@rockthejvm
@rockthejvm 3 года назад
Awesome!
@rheafernandeshallu
@rheafernandeshallu 3 года назад
Thanks a lot :). I learnt something completely new today
@rockthejvm
@rockthejvm 3 года назад
That's my goal!
@viddyasagarverma3722
@viddyasagarverma3722 4 года назад
As always very well explained. Thank you.
@mompyish
@mompyish 3 года назад
I read effective java to thousand articles .Contra-variance remained a puzzle.I think today it sinked in.Thanks.
@rockthejvm
@rockthejvm 3 года назад
That's the goal!
@philipkononenko4942
@philipkononenko4942 3 года назад
Thanks for the video! Great explanation
@rockthejvm
@rockthejvm 3 года назад
Glad it helped!
@mohamadbilal54
@mohamadbilal54 4 года назад
Thank you very much, it's very valuable
@rockthejvm
@rockthejvm 4 года назад
glad to hear it!
@SuperSam4y0u
@SuperSam4y0u 3 года назад
Very helpful, thankyou so much!
@rockthejvm
@rockthejvm 3 года назад
Glad it helped!
@RajeshSamson
@RajeshSamson 3 года назад
I guess no one in RU-vid will explain as you do🤩🤩
@rockthejvm
@rockthejvm 3 года назад
Massive thanks!
@radool22
@radool22 Год назад
The explanation makes perfect sense but couldn’t you just as easily have defined a Vet that supports a method heal of type animal? What benefit does specifying contra bring here? Covariant Vet[T
@rockthejvm
@rockthejvm Год назад
No, because each T is different. Variance is all about the ability to replace a Vet of a type, with a Vet of another type.
@puraniksaket
@puraniksaket 4 года назад
amazing
@XeonFGT
@XeonFGT 2 года назад
Excellent explanation!
@YouTikki
@YouTikki 3 года назад
Thank you sir :)
@rockthejvm
@rockthejvm 3 года назад
Glad it helped!
@erkanaslanel8084
@erkanaslanel8084 3 года назад
God bless you :)
@rockthejvm
@rockthejvm 3 года назад
Thank you!
@slisnychyi
@slisnychyi 3 года назад
really best explanation
@rockthejvm
@rockthejvm 3 года назад
Glad you liked it!
@ColibrisMusicLive
@ColibrisMusicLive Год назад
could you give an example why would one need vet: Vet[Dog] and not vet: Vet[Animal]?
@rockthejvm
@rockthejvm Год назад
It's the same problem in OOP - why would you specifically need a Dog when you can program against the Animal interface? With contravariance, it's the same question, in reverse.
@hgfuhgvg
@hgfuhgvg 3 года назад
I wish I could give more likes
@jewelleharper6285
@jewelleharper6285 2 года назад
Great Videos, however... I would most definitely not call it "Lucky" or fortunate to be Lakia to die of asphyxiation and overheating... Also Hachi is an incredibly sad movie...
@slack128
@slack128 3 года назад
The link no longer works.
@rockthejvm
@rockthejvm 3 года назад
Fixed!
@hgfuhgvg
@hgfuhgvg 3 года назад
ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-b1ftkK1zhxI.html maybe better to clarify that the type List is COVARIANT (and not the type Animal)
@DiegoFerreiradaSilva
@DiegoFerreiradaSilva 4 года назад
amazing
Далее
This Doesn't Make Sense - Scala Loops
13:20
Просмотров 7 тыс.
Covariance and Contravariance
13:31
Просмотров 13 тыс.
Structuring Services in Scala with ZIO and ZLayer
34:29
What the Functor? | Functors in Scala | Rock the JVM
24:43
Variance... without Generics!
9:01
Просмотров 6 тыс.
3 Tricks with Call-by-Name in Scala | Rock the JVM
12:58
What is a Monad? - Computerphile
21:50
Просмотров 600 тыс.
Algebraic Data Types (ADT) in Scala | Rock the JVM
14:19
Turns out REST APIs weren't the answer (and that's OK!)
10:38