Skip to content

Commit 2660cb0

Browse files
committed
Add docstrings for isequal() and isless() on Nullables
1 parent 4046cd9 commit 2660cb0

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

base/nullable.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ null_safe_op{S<:NullSafeTypes,
9898
null_safe_op{S<:NullSafeTypes,
9999
T<:NullSafeTypes}(::typeof(isequal), ::Type{Rational{S}}, ::Type{Rational{T}}) = true
100100

101+
"""
102+
isequal(x::Nullable, y::Nullable)
103+
104+
If neither `x` nor `y` is null, compare them according to their values
105+
(i.e. `isequal(get(x), get(y))`). Else, return `true` if both arguments are null,
106+
and `false` if one is null but not the other: nulls are considered equal.
107+
"""
101108
function isequal{S,T}(x::Nullable{S}, y::Nullable{T})
102109
if null_safe_op(isequal, S, T)
103110
(x.isnull & y.isnull) | (!x.isnull & !y.isnull & isequal(x.value, y.value))
@@ -117,6 +124,14 @@ null_safe_op{S<:NullSafeTypes,
117124
null_safe_op{S<:NullSafeTypes,
118125
T<:NullSafeTypes}(::typeof(isless), ::Type{Rational{S}}, ::Type{Rational{T}}) = true
119126

127+
"""
128+
isless(x::Nullable, y::Nullable)
129+
130+
If neither `x` nor `y` is null, compare them according to their values
131+
(i.e. `isless(get(x), get(y))`). Else, return `true` if only `y` is null, and `false`
132+
otherwise: nulls are always considered greater than non-nulls, but not greater than
133+
another null.
134+
"""
120135
function isless{S,T}(x::Nullable{S}, y::Nullable{T})
121136
# NULL values are sorted last
122137
if null_safe_op(isless, S, T)

doc/stdlib/base.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,12 +263,24 @@ All Objects
263263

264264
Scalar types generally do not need to implement ``isequal`` separate from ``==``\ , unless they represent floating-point numbers amenable to a more efficient implementation than that provided as a generic fallback (based on ``isnan``\ , ``signbit``\ , and ``==``\ ).
265265

266+
.. function:: isequal(x::Nullable, y::Nullable)
267+
268+
.. Docstring generated from Julia source
269+
270+
If neither ``x`` nor ``y`` is null, compare them according to their values (i.e. ``isequal(get(x), get(y))``\ ). Else, return ``true`` if both arguments are null, and ``false`` if one is null but not the other: nulls are considered equal.
271+
266272
.. function:: isless(x, y)
267273

268274
.. Docstring generated from Julia source
269275
270276
Test whether ``x`` is less than ``y``\ , according to a canonical total order. Values that are normally unordered, such as ``NaN``\ , are ordered in an arbitrary but consistent fashion. This is the default comparison used by ``sort``\ . Non-numeric types with a canonical total order should implement this function. Numeric types only need to implement it if they have special values such as ``NaN``\ .
271277

278+
.. function:: isless(x::Nullable, y::Nullable)
279+
280+
.. Docstring generated from Julia source
281+
282+
If neither ``x`` nor ``y`` is null, compare them according to their values (i.e. ``isless(get(x), get(y))``\ ). Else, return ``true`` if only ``y`` is null, and ``false`` otherwise: nulls are always considered greater than non-nulls, but not greater than another null.
283+
272284
.. function:: ifelse(condition::Bool, x, y)
273285

274286
.. Docstring generated from Julia source

doc/stdlib/stacktraces.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* ``func::Symbol``
1818

1919
The name of the function containing the execution context.
20-
* ``linfo::Nullable{MethodInstance}``
20+
* ``linfo::Nullable{Core.MethodInstance}``
2121

2222
The MethodInstance containing the execution context (if it could be found).
2323
* ``file::Symbol``

0 commit comments

Comments
 (0)