There is no pattern matching in Kotlin yet, and language developers are not going to ship this feature soon. But it still very useful one, especially in functional programming. Is it possible to implement pattern matching with no compiler support?
We have Optics for this, it's as close as you'll get today.
Thank you for the answer!
Could you please provide an example of how to use Optics this way?
Yep, the Docs would be a good starting point: https://arrow-kt.io/docs/optics/dsl/
Java 15/16 is getting true pattern matching (destructuring/nested destructuring + instanceof type test) in switch blocks and in ifs ()
https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html
So Kotlin will probably get it too around that time.
EDIT -> pattern matching (deconstruction) has been removed from the JEP in ifs targeting java 15 :'(
So it seems that pattern matching will not be available in java before java 16... hence why an arrow meta plugin would be useful :) @pakoito
I just stumbled across this thread and wanted to say there is now work going on in this direction in arrow meta (https://github.com/arrow-kt/arrow-meta/pull/651 , though it is still very early). Additionally, a few weeks ago I submited KEEP 213.
Most helpful comment
I just stumbled across this thread and wanted to say there is now work going on in this direction in arrow meta (https://github.com/arrow-kt/arrow-meta/pull/651 , though it is still very early). Additionally, a few weeks ago I submited KEEP 213.