Skip to content

Commit 0454007

Browse files
xorJanetkelman
authored andcommitted
Augment docstring for Nullable() and move inline; fix doctests for isnull(). (JuliaLang#19067)
1 parent 2c5a2ed commit 0454007

File tree

4 files changed

+63
-20
lines changed

4 files changed

+63
-20
lines changed

base/docs/helpdb/Base.jl

-9
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,6 @@ Subtraction operator.
197197
"""
198198
-(x, y)
199199

200-
"""
201-
Nullable(x)
202-
203-
Wrap value `x` in an object of type `Nullable`, which indicates whether a value is present.
204-
`Nullable(x)` yields a non-empty wrapper, and `Nullable{T}()` yields an empty instance of a
205-
wrapper that might contain a value of type `T`.
206-
"""
207-
Nullable
208-
209200
"""
210201
bits(n)
211202

base/nullable.jl

+34-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
immutable NullException <: Exception
44
end
55

6+
"""
7+
Nullable(x, hasvalue::Bool=true)
8+
9+
Wrap value `x` in an object of type `Nullable`, which indicates whether a value is present.
10+
`Nullable(x)` yields a non-empty wrapper and `Nullable{T}()` yields an empty instance of a
11+
wrapper that might contain a value of type `T`.
12+
13+
`Nullable(x, false)` yields `Nullable{typeof(x)}()` with `x` stored in the result's `value`
14+
field.
15+
16+
# Examples
17+
18+
```jldoctest
19+
julia> Nullable(1)
20+
Nullable{Int64}(1)
21+
22+
julia> Nullable{Int64}()
23+
Nullable{Int64}()
24+
25+
julia> Nullable(1, false)
26+
Nullable{Int64}()
27+
28+
julia> dump(Nullable(1, false))
29+
Nullable{Int64}
30+
hasvalue: Bool false
31+
value: Int64 1
32+
```
33+
"""
634
Nullable{T}(value::T, hasvalue::Bool=true) = Nullable{T}(value, hasvalue)
735
Nullable() = Nullable{Union{}}()
836

@@ -100,18 +128,20 @@ unsafe_get(x) = x
100128
Return whether or not `x` is null for [`Nullable`](:obj:`Nullable`) `x`; return
101129
`false` for all other `x`.
102130
131+
# Examples
132+
103133
```jldoctest
104134
julia> x = Nullable(1, false)
105-
Nullable{Int64}(1)
135+
Nullable{Int64}()
106136
107137
julia> isnull(x)
108-
false
138+
true
109139
110140
julia> x = Nullable(1, true)
111-
Nullable{Int64}()
141+
Nullable{Int64}(1)
112142
113143
julia> isnull(x)
114-
true
144+
false
115145
116146
julia> x = 1
117147
1

doc/manual/types.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ You can safely access the value of a :obj:`Nullable` object using :func:`get`:
14871487

14881488
julia> get(Nullable{Float64}())
14891489
ERROR: NullException()
1490-
in get(::Nullable{Float64}) at ./nullable.jl:62
1490+
in get(::Nullable{Float64}) at ./nullable.jl:90
14911491
...
14921492

14931493
julia> get(Nullable(1.0))

doc/stdlib/base.rst

+28-6
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,31 @@ Syntax
815815
Nullables
816816
---------
817817

818-
.. function:: Nullable(x)
818+
.. function:: Nullable(x, hasvalue::Bool=true)
819819

820820
.. Docstring generated from Julia source
821821
822-
Wrap value ``x`` in an object of type ``Nullable``\ , which indicates whether a value is present. ``Nullable(x)`` yields a non-empty wrapper, and ``Nullable{T}()`` yields an empty instance of a wrapper that might contain a value of type ``T``\ .
822+
Wrap value ``x`` in an object of type ``Nullable``\ , which indicates whether a value is present. ``Nullable(x)`` yields a non-empty wrapper and ``Nullable{T}()`` yields an empty instance of a wrapper that might contain a value of type ``T``\ .
823+
824+
``Nullable(x, false)`` yields ``Nullable{typeof(x)}()`` with ``x`` stored in the result's ``value`` field.
825+
826+
**Examples**
827+
828+
.. doctest::
829+
830+
julia> Nullable(1)
831+
Nullable{Int64}(1)
832+
833+
julia> Nullable{Int64}()
834+
Nullable{Int64}()
835+
836+
julia> Nullable(1, false)
837+
Nullable{Int64}()
838+
839+
julia> dump(Nullable(1, false))
840+
Nullable{Int64}
841+
hasvalue: Bool false
842+
value: Int64 1
823843

824844
.. function:: get(x::Nullable[, y])
825845

@@ -833,19 +853,21 @@ Nullables
833853
834854
Return whether or not ``x`` is null for :obj:`Nullable` ``x``\ ; return ``false`` for all other ``x``\ .
835855

856+
**Examples**
857+
836858
.. doctest::
837859

838860
julia> x = Nullable(1, false)
839-
Nullable{Int64}(1)
861+
Nullable{Int64}()
840862

841863
julia> isnull(x)
842-
false
864+
true
843865

844866
julia> x = Nullable(1, true)
845-
Nullable{Int64}()
867+
Nullable{Int64}(1)
846868

847869
julia> isnull(x)
848-
true
870+
false
849871

850872
julia> x = 1
851873
1

0 commit comments

Comments
 (0)