File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ struct IsOkError <: InternalPrelude.Exception
3535end
3636
3737function map end
38+ function astuple end
3839
3940macro and_return end
4041function var"@?" end
Original file line number Diff line number Diff line change @@ -161,6 +161,15 @@ macro or(ex, rest...)
161161 end
162162end
163163
164+ function Try. astuple (result)
165+ br = branch (result)
166+ if br isa Break
167+ ()
168+ else
169+ (valueof (br),)
170+ end
171+ end
172+
164173# ##
165174# ## Currying
166175# ##
Original file line number Diff line number Diff line change 1+ Try.astuple(result) -> (value,) or ()
2+ Try.astuple(Ok(value)) -> (value,)
3+ Try.astuple(::Err) -> ()
4+ Try.astuple(Some(value)) -> (value,)
5+ Try.astuple(nothing) -> ()
6+
7+ Return a singleton tuple with the value if the result is "successful"; return an empty tuple
8+ otherwise.
9+
10+ # Examples
11+ ``` julia
12+ julia> using Try
13+
14+ julia> Try. astuple (Ok (1 ))
15+ (1 ,)
16+
17+ julia> Try. astuple (Err (1 ))
18+ ()
19+
20+ julia> Try. astuple (Some (1 ))
21+ (1 ,)
22+
23+ julia> Try. astuple (nothing )
24+ ()
25+ ```
You can’t perform that action at this time.
0 commit comments