Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

A .match "method" just opens the dam to "why stop there?"

I prefer Kotlin's general approach of .let and similar:

    number = foo.bar().baz().let {
      match it {
        A => 1
        B => 2
      }
    }
Now anyone has the general tool for chaining without needing library authors or language designers to create the API for them.


Neat! When working with Options/Results/Iterators, you can use `.map` [1] for exactly this purpose. It would sometimes be convenient to have something like `.map` / `.let` on unwrapped values as well.

[1] https://doc.rust-lang.org/std/option/enum.Option.html#method..., https://doc.rust-lang.org/std/result/enum.Result.html#method..., https://doc.rust-lang.org/std/iter/trait.Iterator.html#metho...


Note that in Rust, `.match` would itself provide the general way:

    let number = foo.bar().baz().match { it =>
        it + 1
    };




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: