Skip to content

Commit

Permalink
Add something (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
nalimilan authored and martinholters committed Jun 1, 2018
1 parent 1feafe9 commit 87b91d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ Currently, the `@compat` macro supports the following syntaxes:

* `isbits(t::Type)` is now `isbitstype(t)` ([#26850]).

* `something` to get the first argument different from `nothing`, unwrapping those
of the `Some` type ([#27258]).

## Renaming

* `Display` is now `AbstractDisplay` ([#24831]).
Expand Down Expand Up @@ -637,3 +640,4 @@ includes this fix. Find the minimum version from there.
[#26670]: https://github.com/JuliaLang/julia/issues/26670
[#26850]: https://github.com/JuliaLang/julia/issues/26850
[#27077]: https://github.com/JuliaLang/julia/issues/27077
[#27258]: https://github.com/JuliaLang/julia/issues/27258
8 changes: 8 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,14 @@ end
export @cfunction
end

if VERSION < v"0.7.0-DEV.5278"
something() = throw(ArgumentError("No value arguments present"))
something(x::Nothing, y...) = something(y...)
something(x::Some, y...) = x.value
something(x::Any, y...) = x
export something
end

include("deprecated.jl")

end # module Compat
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1743,4 +1743,10 @@ let ptr = @cfunction(+, Int, (Int, Int))
@test ccall(ptr, Int, (Int, Int), 2, 3) == 5
end

# 0.7.0-DEV.5278
@test something(nothing, 1) === 1
@test something(Some(2)) === 2
@test something(Some(2), 1) === 2
@test something(nothing, Some(1)) === 1

nothing

0 comments on commit 87b91d5

Please sign in to comment.