ResultTypes.jl icon indicating copy to clipboard operation
ResultTypes.jl copied to clipboard

Propagation syntax

Open jtrakk opened this issue 4 years ago • 2 comments

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

jtrakk avatar Aug 28 '21 00:08 jtrakk

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

keorn avatar Aug 27 '24 10:08 keorn

@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 

0x0f0f0f avatar Aug 27 '24 11:08 0x0f0f0f