Smart Matching

Learn how to match operands in an efficient manner.

Smart match operator

The smart match operator, ~~, compares two operands and returns a true value if they match. The type of comparison depends on the type of both operands. given-when performs an implicit smart match.

This feature is experimental. The details of the current design are complex and unwieldy, and no proposal for simplifying things has gained enough popular support to warrant the feature’s overhaul. The more complex our operands, the more likely we are to receive confusing results. Avoid comparing objects and stick to simple operations between two scalars or one scalar and one aggregate for the best results.

The smart match operator is an infix operator:

Get hands-on with 1200+ tech skills courses.