iamed2 / ResultTypes.jl

A Result type for Julia—it's like Nullables for Exceptions
Other
94 stars 9 forks source link

Propagation syntax #23

Open jtrakk opened 3 years ago

jtrakk commented 3 years ago

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

keorn commented 2 weeks ago

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

0x0f0f0f commented 2 weeks ago

@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