Skip to content

Commit

Permalink
Merge #371
Browse files Browse the repository at this point in the history
371: Use external `@something` r=mattBrzezinski a=omus

Replaces the definition of `@something` with the one [from base](JuliaLang/julia#40729) or [from Compat.jl](JuliaLang/Compat.jl#742).

Co-authored-by: Curtis Vogt <[email protected]>
  • Loading branch information
bors[bot] and omus authored May 27, 2021
2 parents fa00574 + 0fc6a77 commit 7a5fe1a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
XMLDict = "228000da-037f-5747-90a9-8195ccbf91a5"

[compat]
Compat = "3"
Compat = "3.29"
GitHub = "5"
HTTP = "0.9.6"
IniFile = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion src/AWS.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module AWS

using Compat: Compat
using Compat: Compat, @something
using Base64
using Dates
using HTTP
Expand Down
37 changes: 0 additions & 37 deletions src/utilities/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,40 +99,3 @@ function _generate_rest_resource(request_uri::String, args::AbstractDict{String,

return request_uri
end


"""
@something(x, y...)
Short-circuiting version of [`something`](@ref something).
# Examples
```
julia> f(x) = (println("f(\$x)"); nothing);
julia> a = 1;
julia> a = @something a f(2) f(3) error("Unable to find default for `a`")
1
julia> b = nothing;
julia> b = @something b f(2) f(3) error("Unable to find default for `b`")
f(2)
f(3)
ERROR: Unable to find default for `b`
...
julia> b = @something b f(2) f(3) Some(nothing)
f(2)
f(3)
```
"""
macro something(args...)
expr = :(nothing)
for arg in reverse(args)
expr = :((val = $arg) !== nothing ? val : $expr)
end
return esc(:(something(let val; $expr; end)))
end
10 changes: 0 additions & 10 deletions test/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,3 @@ end

@test AWS._merge("a", "b") == expected
end

@testset "@something" begin
@test_throws ArgumentError AWS.@something()
@test_throws ArgumentError AWS.@something(nothing)
@test AWS.@something(1) === 1
@test AWS.@something(Some(nothing)) === nothing

@test AWS.@something(1, error("failed")) === 1
@test_throws ErrorException AWS.@something(nothing, error("failed"))
end

0 comments on commit 7a5fe1a

Please sign in to comment.