Fun with Function Types in Kotlin

Поделиться
HTML-код
  • Опубликовано: 24 дек 2024

Комментарии • 43

  • @aabhishek4911
    @aabhishek4911 Месяц назад +23

    Just when I thought I knew everything about function types

    • @typealias
      @typealias  Месяц назад +6

      Lots of neat little tricks just waiting to be exploited! 🙂

  • @HoussamElbadissi
    @HoussamElbadissi Месяц назад +6

    Great video as usual!
    Looking back, I used the implicit switching between extension and non-extension functions many times before without even realizing it!
    Also didn't know you could take references to property setters/getters, that's pretty neat!

  • @AleksandrIasinskii
    @AleksandrIasinskii Месяц назад +1

    Hey Dave!
    I just wanted to say thank you for your wonderful book and videos. It really helps!

    • @typealias
      @typealias  Месяц назад +1

      Thank you for your kind words, Aleksandr! I'm so glad you've been enjoying them.

  • @smreha
    @smreha 19 дней назад

    All the things are neat. It would be great if you also explain each of such cool language features with a practical use case.

  • @PedroBarbosaRoman
    @PedroBarbosaRoman Месяц назад +2

    Every time I think I will know everything in the video, you surprise me! I've always wanted to know if using these types of references are we doing any kind of reflection or not, since the symbol is the same

    • @typealias
      @typealias  Месяц назад +3

      If you don't explicitly specify a type (e.g., `val x = ::countWords`), then a function reference will be one of the `KFunctionN` types, which gives you access to reflection properties and functions. But unless you've got the `kotlin-reflect` library added to your project, you'll really only have access to the `name`. Stay tuned - I've got a video queued up that explains all of this further... won't be the next video, but probably the one after that.

  • @teenriot-de
    @teenriot-de Месяц назад +6

    I like that you use one line property delegation by: val length get() = text.length
    I switched to an even shorter form: val length by text::length
    Advantage is that it is still one liner for var properties.

    • @typealias
      @typealias  Месяц назад +2

      Ooooh! I like that! I'm going to start using that! 😁

    • @teenriot-de
      @teenriot-de Месяц назад +1

      @@typealias I dont know if there is a difference in bytecode. But i believe in the power of the incredible compiler superman architects.

    • @typealias
      @typealias  Месяц назад

      😂

    • @HoussamElbadissi
      @HoussamElbadissi Месяц назад

      Oh God that's so gorgeous!

  • @DaleHawkins
    @DaleHawkins Месяц назад +1

    Thanks!

    • @typealias
      @typealias  Месяц назад

      Hey Dale! That's very kind of you. Thank you so much! 🎉

  • @RickertBrandsen
    @RickertBrandsen Месяц назад

    really interesting one. Some things are really ez in kotlin, but some things are blewing my mind still to this day. Thank you Dave. Really Gucci stuff.

    • @typealias
      @typealias  Месяц назад

      Thanks so much! So many fun things to discover in Kotlin!

  • @TimSchraepen
    @TimSchraepen Месяц назад +1

    Damn that’s neat!
    My mind was racing with practical applications to try out

    • @typealias
      @typealias  Месяц назад

      Let me know what ideas you come up with!

  • @fabricehategekimana5350
    @fabricehategekimana5350 Месяц назад

    This video is incredible ! I love your way of explaining things, we really feel you have a passion for that. I wanted to know what do you think about uniform function call from some languages like Nim ?

    • @typealias
      @typealias  Месяц назад +1

      Hey, thanks so much, Fabrice! I appreciate your kind words! Although I haven't got much experience with languages that support uniform function call syntax, in concept I like the convenience of it. Of course, it's not always natural for the first parameter to be used as a receiver - e.g., `createUser(firstName, lastName, age)` would be confusing as `firstName.createUser(lastName, age)` - so regardless of whether the developer has to opt in to the "method" syntax or whether the language gives it to you out of the box, developers still need to use discretion. Have you got thoughts about it yourself?

    • @fabricehategekimana5350
      @fabricehategekimana5350 Месяц назад

      @typealias thanks for your feedback ! I thought the same ! I implemented it for a language I am building (still far from finished because of the complexity of different features I joined together ^^')
      It's quite convenient since you can switch between a normal call (f(x)), it's "method call" (x.f()), it's pipe call (x |> f()) or his arrays versions (f#([x]), [x].f#(), [x] |> f#()). But when it's too convient, that can mean there is a potential problem. That's why I wanted to know how kotlin functions works to see if there is a benefit (security, efficiency, etc.) in the way it does things. Actually I don't really know🤔

  • @robchr
    @robchr Месяц назад

    This is all cool and clever but if I ever saw this in a PR, I was kick it back.

    • @typealias
      @typealias  Месяц назад

      Certainly a feature to be used judiciously

  • @lifeguard0108
    @lifeguard0108 Месяц назад +3

    Wow thank you.

  • @laughordietrying5226
    @laughordietrying5226 Месяц назад

    Amazing video, thanks for sharing :)
    i have a question for the last example, using Lamdas with receivers u can pretty do everything extension function do ? If so what is the difference between them ?

    • @typealias
      @typealias  Месяц назад

      Hey, thanks so much! The differences between a lambda with a receiver and an extension function are essentially the same as the differences between a regular lambda and a regular function. The biggest differences are that a lambda is an expression, the `return` works differently in a lambda than a function, and lambdas require type inference to determine a return type and receiver type. You'll see some of those differences demonstrated in next week's video.

    • @laughordietrying5226
      @laughordietrying5226 Месяц назад

      @@typealias Thank u very much :), can't wait for next week vid

  • @ArthurKhazbs
    @ArthurKhazbs Месяц назад

    Great stuff, as usual! Thank you so much, Dave!

    • @typealias
      @typealias  Месяц назад

      Thanks so much, Arthur!

  • @StefanoGroenland
    @StefanoGroenland Месяц назад

    Great video! Do you have any resources or plans on using Socket Servers within kotlin? After learning all these things i’m looking into sockets for sending “commands” between my projects to act upon!

    • @typealias
      @typealias  Месяц назад

      Hey Stefano! I've used websockets with Ktor ( ktor.io/docs/server-websockets.html ) for that kind of thing, but pretty sure I'll end up updating those projects to use kotlinx.rpc ( github.com/Kotlin/kotlinx-rpc ) once that project is a little farther along. I showcased some of kotlinx.rpc in a livestream a few months back. You can jump to that segment here: ruclips.net/user/liveS_JKbmN_A8o?feature=shared&t=389

  • @devopsthinh
    @devopsthinh Месяц назад +1

    Thanks, from Vietnam😘

  • @Shamil_gulmetov
    @Shamil_gulmetov Месяц назад +2

    Thank you

  • @osisuper98
    @osisuper98 28 дней назад

    You are the best man

  • @mankinPT
    @mankinPT Месяц назад

    TIL... Continue with the awesome content

  • @bharathv97
    @bharathv97 Месяц назад +2

    This is fun 😀

  • @saxintosh
    @saxintosh Месяц назад +1

    you're good!!! 🤣

  • @LightDante
    @LightDante Месяц назад

    This is a little bit advanced for me

  • @Z1ew-k1q
    @Z1ew-k1q Месяц назад

    why not you become kotlin team lead, senior manage CEO , CTO and all other position at jet brains

    • @typealias
      @typealias  Месяц назад +2

      Hey, that's kind of you to say! That'd be a lot of responsibility, though... so I'm going to stick to making videos! 🙂

    • @Z1ew-k1q
      @Z1ew-k1q Месяц назад

      but you will take kotlin to 1# loved lanuage

  • @hinocenciopaulo
    @hinocenciopaulo Месяц назад

    I just realized that I don't know shit about Kotlin functions...