15
Sep 15

Better Scala pattern matching with erasure

With many beautiful and some rather repulsive elements in Scala pattern matching is definitely the former. Unfortunately, due to Scala’s reliance on the JVM it suffers from [type erasure].

Scala’s latest editions have an improved reflection facility that allows you to retain types and then use them at runtime.

Below is an example of using TypeTag to pattern match types at various depths. [I’m actually pattern matching Java’s collection types here].

Tags: ,

Leave a comment