Skip to content

Commit f011893

Browse files
committed
Document is_error and fix is_none in docs
1 parent 6c8c657 commit f011893

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
@@ -105,11 +105,11 @@ function harmonic_mean(v::AbstractArray{<:Integer})::Option{Float64}
105105
sm = 0.0
106106
for i in v
107107
invi = safe_div(1, i)
108-
is_none(invi) && return none
108+
is_error(invi) && return none
109109
sm += unwrap(invi)
110110
end
111111
res = safe_div(length(v), sm)
112-
is_none(res) && return none
112+
is_error(res) && return none
113113
return some(unwrap(res))
114114
end
115115
```

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)