File tree 2 files changed +14
-2
lines changed
2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -124,11 +124,11 @@ function harmonic_mean(v::AbstractArray{<:Integer})::Option{Float64}
124
124
sm = 0.0
125
125
for i in v
126
126
invi = safe_div (1 , i)
127
- is_none (invi) && return none
127
+ is_error (invi) && return none
128
128
sm += unwrap (invi)
129
129
end
130
130
res = safe_div (length (v), sm)
131
- is_none (res) && return none
131
+ is_error (res) && return none
132
132
return some (unwrap (res))
133
133
end
134
134
```
Original file line number Diff line number Diff line change @@ -79,6 +79,18 @@ Alias for `Result{T, Nothing}`
79
79
"""
80
80
const Option{T} = Result{T, Nothing}
81
81
82
+ """
83
+ is_error(x::Result)
84
+
85
+ Check if `x` contains an error value.
86
+
87
+ # Example
88
+
89
+ ```jldoctest
90
+ julia> is_error(none(Int)), is_error(some(5))
91
+ (true, false)
92
+ ```
93
+ """
82
94
is_error (x:: Result ) = x. x isa Err
83
95
84
96
Option (x:: Result{T, E} ) where {T, E} = is_error (x) ? none (T) : Option {T} (x. x)
You can’t perform that action at this time.
0 commit comments