Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docstrings in nullable.jl #19067

Merged
merged 1 commit into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,6 @@ Subtraction operator.
"""
-(x, y)

"""
Nullable(x)

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`.
"""
Nullable

"""
bits(n)

Expand Down
38 changes: 34 additions & 4 deletions base/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@
immutable NullException <: Exception
end

"""
Nullable(x, hasvalue::Bool=true)

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`.

`Nullable(x, false)` yields `Nullable{typeof(x)}()` with `x` stored in the result's `value`
field.

# Examples

```jldoctest
julia> Nullable(1)
Nullable{Int64}(1)

julia> Nullable{Int64}()
Nullable{Int64}()

julia> Nullable(1, false)
Nullable{Int64}()

julia> dump(Nullable(1, false))
Nullable{Int64}
hasvalue: Bool false
value: Int64 1
```
"""
Nullable{T}(value::T, hasvalue::Bool=true) = Nullable{T}(value, hasvalue)
Nullable() = Nullable{Union{}}()

Expand Down Expand Up @@ -100,18 +128,20 @@ unsafe_get(x) = x
Return whether or not `x` is null for [`Nullable`](:obj:`Nullable`) `x`; return
`false` for all other `x`.

# Examples

```jldoctest
julia> x = Nullable(1, false)
Nullable{Int64}(1)
Nullable{Int64}()

julia> isnull(x)
false
true

julia> x = Nullable(1, true)
Nullable{Int64}()
Nullable{Int64}(1)

julia> isnull(x)
true
false

julia> x = 1
1
Expand Down
2 changes: 1 addition & 1 deletion doc/manual/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ You can safely access the value of a :obj:`Nullable` object using :func:`get`:

julia> get(Nullable{Float64}())
ERROR: NullException()
in get(::Nullable{Float64}) at ./nullable.jl:62
in get(::Nullable{Float64}) at ./nullable.jl:90
...

julia> get(Nullable(1.0))
Expand Down
34 changes: 28 additions & 6 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -815,11 +815,31 @@ Syntax
Nullables
---------

.. function:: Nullable(x)
.. function:: Nullable(x, hasvalue::Bool=true)

.. Docstring generated from Julia source

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``\ .
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``\ .

``Nullable(x, false)`` yields ``Nullable{typeof(x)}()`` with ``x`` stored in the result's ``value`` field.

**Examples**

.. doctest::

julia> Nullable(1)
Nullable{Int64}(1)

julia> Nullable{Int64}()
Nullable{Int64}()

julia> Nullable(1, false)
Nullable{Int64}()

julia> dump(Nullable(1, false))
Nullable{Int64}
hasvalue: Bool false
value: Int64 1

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

Expand All @@ -833,19 +853,21 @@ Nullables

Return whether or not ``x`` is null for :obj:`Nullable` ``x``\ ; return ``false`` for all other ``x``\ .

**Examples**

.. doctest::

julia> x = Nullable(1, false)
Nullable{Int64}(1)
Nullable{Int64}()

julia> isnull(x)
false
true

julia> x = Nullable(1, true)
Nullable{Int64}()
Nullable{Int64}(1)

julia> isnull(x)
true
false

julia> x = 1
1
Expand Down