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

Propagation syntax #23

Open
jtrakk opened this issue Aug 28, 2021 · 2 comments
Open

Propagation syntax #23

jtrakk opened this issue Aug 28, 2021 · 2 comments

Comments

@jtrakk
Copy link

jtrakk commented Aug 28, 2021

Rust has a syntactic shortcut for propagating errors. Would a similar operator work in ResultTypes.jl?

@keorn
Copy link

keorn commented Aug 27, 2024

There is already @try is this requesting something even shorter?

@0x0f0f0f
Copy link
Collaborator

@keorn @jtrakk @iamed2 I think a pipe-like |> syntax would be really nice.

I'm just using ⇶ (really ugly) as an example operator because we don't have any "cool" extra pipe operator that is available to bind. See this https://discourse.julialang.org/t/list-of-binary-infix-operators/32282/2

Something like this would be really handy. Just like rust's ?.

f(a::Int)::Result{Int, SomeError} = div(3, a)
g(a::Int)::Result{Int, SomeError} = a*2

h(x::Int) = f(x) ⇶ g # returns the f's error if x is 0, but unwraps result and passes it to g otherwise 

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

3 participants