Function arguments with multiple names

I’d like to use a function with multiple data sources that have slightly different parameter names.
Is there something like

function f(; end_date {alternates: endDate, eDate, EndDt }, start_date="1Jan2020" )

where end_date is the term used within the function, endDate, eDate, EndDt are alternatives for calling the function. The function requires exactly 1 of the 4 terms to be specified

f( end_date   = "1Jan2030" )    #works
f( endDate    = "1Jan2030" )    #works
f( eDate      = "1Jan2030" )    #works
f( EndDt      = "1Jan2030" )    #works

f( )  #error end_date not specified
f( end_date = "1Jan2030", EndDt      = "1Jan2030" )    #error  end_date  parameter specified twice.
# `get_end_date` checks that exactly 1 argument is not `nothing`, and returns that 1 argument.
get_end_date(a, ::Nothing, ::Nothing, ::Nothing) = a
get_end_date(::Nothing, b, ::Nothing, ::Nothing) = b
get_end_date(::Nothing, ::Nothing, c, ::Nothing) = c
get_end_date(::Nothing, ::Nothing, ::Nothing, d) = d

# `f` is the interface function
function f(; end_date = nothing, endDate = nothing, eDate = nothing, EndDt = nothing)
    _f(get_end_date(end_date, endDate, eDate, EndDt))
end
function _f(end_date)
    ... # uses the end date
end

If you prefer, a more general definition of get_end_date:

function get_end_date(vargs::Vararg{Any,K}) where {K}
    choose = map(!isnothing, vargs)
    @assert sum(choose) == 1
    @inbounds vargs[findfirst(choose)::Int]
end
1 Like

Interesting thank you.