Broadening Pattern Matching

Mark "Justin" Waks
1 min readFeb 14, 2019

--

A quick update in the Dotty News department: the pre-SIP discussion has begun for Dotty’s name-based pattern matching.

I don’t have much to add to the links above, which are worth reading, but the tl;dr (as I understand it) is that Scala 2’s pattern-matching approach (that you write extractors that return specific types) is being replaced by a name-based approach that lets you return types that have specific names of methods. So instead of having to specifically return Option, you have to return a type that has get and isEmpty members.

In that sense, it’s similar to the way for comprehensions work: theoretically, you feed Monads into for comprehensions, but in reality you can give them anything that looks like a Monad — types with map, flatMap, foreach and/or withFilter methods, depending on what you do in your for.

It’s more general than the existing scheme, and should allow for lower-overhead extractors when that matters. Seems like a win to me, but if you have thoughts or opinions, I recommend checking out the discussion…

--

--

Mark "Justin" Waks
Mark "Justin" Waks

Written by Mark "Justin" Waks

Lifelong programmer and software architect, specializing in online social tools and (nowadays) Scala. Architect of Querki (“leading the small data revolution”).

No responses yet