KotlinConf 2018 - Sealed Classes Opened My Mind: How We Use Kotlin to Tame State at Etsy by Patrick

  • Published on Oct 14, 2018
  • Recording brought to you by American Express americanexpress.io/kotlin-jobs
    The talk explores using sealed classes to represent state via an event stream and how we can take filtered views of it while still maintaining the exhaustiveness of when. The talk would follow the concepts outlined in my post here: codeascraft.com/2018/04/12/se...

    Additionally it would explore how to use RxJava to emit these events and how to use when and filterIsInstance to react to them.

    There is a section on how Java's instanceof was often considered a poor practice and the (sometimes painful) indirection of polymorphic solutions like the visitor pattern. And finally how Kotlin makes all that pain go away.

    About Patrick Cousins:
    Been programming for nearly 20 years and I still love rediscovering that passion for new patterns and languages. Fan of corny jokes and seal puns.

Comments • 33

  • Panduka De Silva
    Panduka De Silva 2 years ago +4

    Great talk! but just want to clarify, 'when' expression should not always be exhaustive unless it's in a return expression. There will be just a warning instead

  • Jan Vladimir Mostert
    Jan Vladimir Mostert 2 years ago +15

    Thanks for the great talk!

  • Basil Bourque
    Basil Bourque Year ago +2

    FYI, sealed classes are coming to Java.

  • Saravana Thiyagaraj
    Saravana Thiyagaraj 2 years ago +2

    If it's too much to type, we could always use static imports. It keeps the code clean.

  • Rakhi Dhavale
    Rakhi Dhavale 2 years ago +5

    well explained ! nice talk !

  • Hendra Wijaya Djiono
    Hendra Wijaya Djiono 2 years ago +1

    When I'm trying to replicate the Cancelled object inside of sealed class Result, I can't use `is` inside of the when branch

  • ScrewThursdays

    Ocaml like pattern matching and union types are very cool concept.

  • Ryan Mayobre
    Ryan Mayobre Year ago +1

    Visitor Pattern Link from Patrick's Slide:

  • Hendra Wijaya Djiono
    Hendra Wijaya Djiono 2 years ago +1


  • Thamidu Dharshitha

    Great presentation. I enjoyed alot. But the audience is some bunch of robots with 0 humor. When Patrik try to crack a joke, audience is like (O-O). Then he explains that it is a joke. Feels bad man.

  • Raju Shingadiya
    Raju Shingadiya 2 years ago +6

    Nice ppt with funny stuff

  • Alberto Cavalcante

    Nice talk

  • tubetib
    tubetib Year ago

    I don't understand the .map { it.wool } example with Rx. There is no wool. There is Wool. Missing some context.

  • Paul-Sebastian Manole
    Paul-Sebastian Manole 3 years ago +2

    Kotlin's `when is` -> Rust's `match`

  • bocckoka

    to me these sealed classes look like an ugly syntax for sum types

  • Maxim N
    Maxim N 2 years ago +29

    Tough crowd :(

  • SagaRock101
    SagaRock101 Year ago +1


  • Andrii Iliunin
    Andrii Iliunin 2 years ago +2

    "No need for polymorphism" - sure, object-oriented programming is dead in android, no need for this.

  • chris Athanas

    Ah Um ah um ah um ah um

  • cpaleop
    cpaleop Year ago