Open civitz opened 7 years ago
Key concept: pattern matching in functional languages is total: if an interface can only be implemented by one of N classes, then matching on M<N classes would lead to a partial match, and in functional languages this would trigger a compiler error. In java this is not possible, and slang tries to imitate that via exception (if you use Match.of
) or via the use of Option (if you use Match.option
) for incomplete matches.
Provide a meaningful example of javaslang's structural pattern matching, exploring its benefits.