Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What does this do?

    operator {min, max} := Math
    value min ceiling max floor
Is that a declaration or an invocation?


It's doing a few things at once:

First line:

* `{min, max} := Math` is a destructuring declaration. It's similar to the destructuring assignment `{min, max} = Math` (i.e., `min = Math.min; max = Math.max`), but also declares min and max as const.

* The `operator` prefix means to treat min and max as new infix operators in the rest of the program.

Second line:

Given that min and max are infix operators, `value min ceiling max floor` is equivalent to `max(min(value, ceiling), floor)`. Yes, the latter is gross. That's why we like to write `value min ceiling max floor` instead. Think of it as "value minned with ceilling (i.e. capped at ceiling), then maxed with floor (i.e. prevented from going below floor)".


Don't understand the boner for infix notation, you find an usecase for it like... once every year?


It looks like rubyist brainrot




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: