Recently I was working on a scala project that required parsing text to create case classes that can be treated as commands that get passed to other subsystems. The following string commands had to be mapped into cases classes.
SET foo bar
GET foo
BEGIN
COMMIT
ROLLBACK
END
Following are the case classes the commands needed to be mapped to
Initially I implemented the parsing logic using if else construct and this is what the code looked like
After reimplementing the parsing logic using pattern matching the code is more compact and easier to understand (IMHO)