Skip to content

Commit

Permalink
Add docstrings for isequal() and isless() on Nullables
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan committed Aug 31, 2016
1 parent 6d013c3 commit b2acbeb
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions base/nullable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ typealias NullSafeTypes Union{NullSafeInts, NullSafeFloats}
null_safe_op{S<:NullSafeTypes,
T<:NullSafeTypes}(::typeof(isequal), ::Type{S}, ::Type{T}) = true

"""
isequal(x::Nullable, y::Nullable)
If neither `x` nor `y` is null, compares them according to their values
(i.e. `isless(get(x), get(y))`). Else, returns `true` if both arguments are null,
and `false` if one is null but not the other: nulls are considered equal.
"""
function isequal{S,T}(x::Nullable{S}, y::Nullable{T})
if null_safe_op(isequal, S, T)
(x.isnull & y.isnull) | (!x.isnull & !y.isnull & isequal(x.value, y.value))
Expand All @@ -108,6 +115,14 @@ isequal(x::Nullable{Union{}}, y::Nullable{Union{}}) = true
isequal(x::Nullable{Union{}}, y::Nullable) = y.isnull
isequal(x::Nullable, y::Nullable{Union{}}) = x.isnull

"""
isless(x::Nullable, y::Nullable)
If neither `x` nor `y` is null, compares them according to their values
(i.e. `isless(get(x), get(y))`). Else, returns `true` if only `y` is null, and `false`
otherwise: nulls are always considered greater than non-nulls, but not greater than
another null.
"""
function isless{S,T}(x::Nullable{S}, y::Nullable{T})
# NULL values are sorted last
if null_safe_op(isless, S, T)
Expand Down

0 comments on commit b2acbeb

Please sign in to comment.