Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative value resolution syntax #138

Closed
JorisBlanken opened this issue Apr 11, 2019 · 1 comment
Closed

Alternative value resolution syntax #138

JorisBlanken opened this issue Apr 11, 2019 · 1 comment

Comments

@JorisBlanken
Copy link

JorisBlanken commented Apr 11, 2019

Hello,

In current examples patterns matched show a return statement, I feel it would be both more intuitive and more usefull if the pattern matching statement itselfs resolves a value.

Contrast the following.
Current:

function factorial(n) {
    case (n) {
        when 0 -> return 1
        when n -> return n * factorial(n - 1)
    }
}

Syntax I propose:

function factorial(n) {
    return case(n) {
        when 0 -> 1
        when n -> n * factorial(n - 1)
    }
}

Allows direct assignment to variables:

let foo = true;
let bar = case (foo) {
    when true -> 'Yes'
    when false -> 'No'
}
console.log(bar); // 'Yes'

Allows intuitive integration into lambdas:

const factorial = n => case (n) {
    when 0 -> 1
    when n -> n * factorial(n-1)
}

I would like to hear other's thoughts on this.

Thanks,
Joris

@FireyFly
Copy link

This is what #116 is about--I believe the proposal initially allowed both expressions and statements in the branches unconditionally, which caused problems with things like break and continue. The readme examples with return probably just aren't updated yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants