Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Add unwrap operator #29

Closed
ShadelessFox opened this issue Nov 21, 2020 · 0 comments
Closed

Add unwrap operator #29

ShadelessFox opened this issue Nov 21, 2020 · 0 comments
Assignees
Labels
sugar Things related to enhancing syntax with sugar syntax Things related to the syntax

Comments

@ShadelessFox
Copy link
Owner

An unwrap (?) operator should return early from the function if supplied expression is resulted in none. This could help avoiding writing if x != none everywhere.

Example:

def read_contents() {
    let file = File.open('test.bin')?; # may return early if File.open resulted in `none`
    let data = file.read()?; # may return early if File.read resulted in `none`
    return data;
}

Alternate syntax: The try keyword can be used for unwrapping as an unary operator.

@ShadelessFox ShadelessFox added syntax Things related to the syntax sugar Things related to enhancing syntax with sugar labels Nov 21, 2020
@ShadelessFox ShadelessFox self-assigned this Nov 21, 2020
ShadelessFox added a commit that referenced this issue Nov 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
sugar Things related to enhancing syntax with sugar syntax Things related to the syntax
Projects
None yet
Development

No branches or pull requests

1 participant