Тёмный

Kotlin Context Receivers - How to Use, Why, and Best Practice 

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

blog post: blog.rockthejv...
Complete Kotlin course: rockthejvm.com...
This video is a long-form tutorial on how to use context receivers, a relatively new feature of the Kotlin language.
We talk about
- why context receivers are useful when we need increased (but locally available) abstractions
- how to allow some functionality for some types and not others
- how to control which scopes grant which functionality
- how to disallow compiler-legal but nonsensical calls
- how to not abuse context receivers and do dependency injection right
- some comparisons with Scala, type classes and a version of a pattern called tagless final
We'll look at the need to add extension methods, then the need to abstract extension methods only for some types and not for others. We will introduce the concept of "receiver" and "dispatch receiver" to understand how we can technically solve the problem of selective abstraction.
To overcome the inherent limtations, we'll use context receivers to
- allow some functions for some types and not others
- control which scopes grant which functions
- disallow compiler-legal but non-sensical calls
- implement "implicit" dependency injection
Follow Rock the JVM on:
LinkedIn: / rockthejvm
Twitter: / rockthejvm
Blog: Blog: blog.rockthejv...
-------------------------------------------------------------------------
Home: rockthejvm.com
-------------------------------------------------------------------------

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

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

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

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 8   
@dmytromykhailov-lt5xm
@dmytromykhailov-lt5xm Год назад
Amazingly good timing for this video. I was wrapping my head around context receivers and patterns for business logic organisations in Kotlin last 4 days in a row. Looks like this pattern makes in much easier to use “diamon architecture” that Vlad from devinsideyou was talking. Daniel, thanks for the video it really helps to put the puzzle together after watching it.
@rockthejvm
@rockthejvm Год назад
Glad you like it!
@heartly4u
@heartly4u Год назад
Thank you @Daniel this video is awesome as usual as your other videos. I am big fan of your scala videos, but now it also helps me more and more about kotlin.
@TheProximator
@TheProximator Год назад
Amazing, your videos are very instructive, you are the best :)
@dev_sonu
@dev_sonu 7 месяцев назад
clear explanation, thanks!♥♥
@ss1ss2ss3ss4ss5ss6ss
@ss1ss2ss3ss4ss5ss6ss Год назад
Smart, clear and straight to the point! Keep up the quality!
@tepan
@tepan 4 месяца назад
Mind-blowing! Thank you. At the end, I thought: great, so I can use this "implicit" dependency injection to swap implementations for tests, and I can provide the prod implementation without a DI framework (like Spring Boot). But that's when you made the Jobs repository explicit again. I can't wait to try both methods.
@andromadusnaruto1544
@andromadusnaruto1544 7 месяцев назад
Beautiful explanation! Clear and concise... 👍🏽
Далее
Новая BMW 5 провал за 10 млн! ИЛИ?..
32:07
Barno
00:22
Просмотров 341 тыс.
Microservices and gRPC in Scala with FS2 and Scalapb
27:45
Context Receivers Are Coming to Kotlin!
31:44
Просмотров 37 тыс.
Inline Functions: inline, crossinline, and noinline
11:59
Solving distributed systems challenges in Rust
3:15:52
Просмотров 241 тыс.
Being Competent With Coding Is More Fun
11:13
Просмотров 78 тыс.