Skip to content

Commit

Permalink
Add @Country convenience macro.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Forgy authored and Eric Forgy committed Jul 4, 2020
1 parent 66340c1 commit bbc20ab
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Countries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Licensed under MIT License, see LICENSE.md
"""
module Countries

export Country
export Country, country, @country
export name, code, currencies, dial, capital, continent, isdeveloping, region, subregion

"""
This is a singleton type, intended to be used as a label for dispatch purposes
Expand Down Expand Up @@ -55,6 +56,13 @@ country(S::Symbol) = _country_data[S][1]

country(::Type{C}) where {C<:Country} = C

macro country(syms)
args = syms isa Expr ? syms.args : [syms]
for nam in args
@eval __module__ const $nam = Countries.$nam
end
end

"""
Returns the official name from the UN Statistics Division.
"""
Expand Down Expand Up @@ -109,4 +117,9 @@ end
allsymbols() = keys(_country_data)
allpairs() = pairs(_country_data)

# Contruct cash position types for convenience.
for (s,(cntry,u,c,n)) in Countries.allpairs()
@eval const $s = typeof($(country(cntry))())
end

end # module Countries

0 comments on commit bbc20ab

Please sign in to comment.