Skip to content

Commit c3a7d52

Browse files
committed
Merge branch 'fixiserror'
2 parents a272e65 + f011893 commit c3a7d52

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

docs/src/usage.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ function harmonic_mean(v::AbstractArray{<:Integer})::Option{Float64}
124124
sm = 0.0
125125
for i in v
126126
invi = safe_div(1, i)
127-
is_none(invi) && return none
127+
is_error(invi) && return none
128128
sm += unwrap(invi)
129129
end
130130
res = safe_div(length(v), sm)
131-
is_none(res) && return none
131+
is_error(res) && return none
132132
return some(unwrap(res))
133133
end
134134
```

src/ErrorTypes.jl

+12
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ Alias for `Result{T, Nothing}`
7979
"""
8080
const Option{T} = Result{T, Nothing}
8181

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+
"""
8294
is_error(x::Result) = x.x isa Err
8395

8496
Option(x::Result{T, E}) where {T, E} = is_error(x) ? none(T) : Option{T}(x.x)

0 commit comments

Comments
 (0)