logoalt Hacker News

gedylast Sunday at 4:59 PM3 repliesview on HN

As a former Scala fan, wow you aren't kidding, wth

    val month = i match
        case 1  => "January"
        case 2  => "February"
        // more months here ...
        case 11 => "November"
        case 12 => "December"
        case _  => "Invalid month"  // the default, catch-all
    
    // used for a side effect:
    i match
        case 1 | 3 | 5 | 7 | 9  => println("odd")
        case 2 | 4 | 6 | 8 | 10 => println("even")
    
    // a function written with 'match':
    def isTrueInPerl(a: Matchable): Boolean = a match
        case false | 0 | "" => false
        case _ => true

Replies

jfimlast Sunday at 5:30 PM

It's been a while since I touched Scala but wasn't that a thing in previous versions, minus the braces not being present?

show 1 reply
malkialast Sunday at 9:29 PM

Sorry, I'm coming from C++-ish background - can anyone explain what's going on :)

show 1 reply
bdangubiclast Sunday at 5:06 PM

madness :)

show 1 reply