Implement formatter with pattern matching