Hacker News new | ask | show | jobs
by bfrydl 2541 days ago
Nesting multiple branches of ternary operators doesn't work well but if it's a sort of “if elseif elseif else” situation I think this looks pretty nice:

    x > 0 ? 'positive' :
    x < 0 ? 'negative' :
    'zero'
1 comments

But not nearly as nice as:

    match x {
        0 => 'zero',
        x if x > 0 => 'positive',
        x if x < 0 => 'negative',
    }
I actually made a library for that!

It's published on npm and everything. It's small, a bit unpolished, maybe needs more docs, but it works pretty damn well if you ask me!

https://gitlab.com/svartkonst/match