3 ms·
If Java were to support to scale/fp-like match statements with case objects and unapply methods, it would probably be good enough to obviate Scala (It would sti
by mruts 8y ago
If Java were to support to scale/fp-like match statements with case objects and unapply methods, it would probably be good enough to obviate Scala (It would still be distinctly worse though).
Pattern matching is such a powerful feature. I wish more languages (like python) would realize it’s value and add it.
- paulddraper 8y agoIs it? I've used Scala before. There are some cases, like compilers where I could see matching and extracting complex and nested patterns to be useful. But in most cases monadic operations/functors plus if/else seems pretty much as good.
- mruts 8y agoUnfortunately monads aren’t in base scala (as an explicit class at least), so often you need to do some ad-hoc pattern matching on tuples or data structures and pattern matching really helps in de-structuring and binding relevant variables. I probably use monadic operations (map, fold, etc) at least 5-10 times a day in my job (I’m a scala dev), and match expressions at least 3-5 times a day. So pretty useful I’d say. Though then again I’m dealing with some pretty baroque case classes that contain dozens of values of financial information.
- paulddraper 8y ago> Unfortunately monads aren’t in base scala (as an explicit class at least) Scalaz and cats are perhaps the most common dependencies in the Scala ecosystem.
- Joeri 8y agoI suspect trying to combine pattern matching with java’s container classes would be an exercise in frustration. What struck me about scala was how much nicer its standard library is, even when using only things java has equivalents for.
- meddlepal 8y agoThis is on the roadmap.
- Polyisoprene 8y agoHopefully project Amber will arrive soon. https://cr.openjdk.java.net/~briangoetz/amber/pattern-match.html https://cr.openjdk.java.net/~briangoetz/amber/pattern-match....