JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.41k stars 5.45k forks source link

Add curried versions of getproperty and getfield #42629

Open krrutkow opened 2 years ago

krrutkow commented 2 years ago

In the spirit of having curried versions builtin functions (#32018, #36163, #36759, https://github.com/JuliaLang/julia/issues/42485#issuecomment-933010383, etc.), I often want to use something like getproperty(:field) and getfield(:field) instead of defining x -> x.field so often. getfield is a builtin and faces the same implementation challenges as isa, ===, etc.

Perhaps there could be one overarching issue to list/track the subset of builtin functions that should have curried versions implemented?

julia> subtypes(Core.Builtin)
36-element Vector{Any}:
 Core.IntrinsicFunction
 Core.var"##invoke"
 typeof(<:)
 typeof(===)
 typeof(Core._abstracttype)
 typeof(Core._apply_iterate)
 typeof(Core._apply_pure)
 typeof(Core._call_in_world)
 typeof(Core._call_latest)
 typeof(Core._equiv_typedef)
 typeof(Core._expr)
 typeof(Core._primitivetype)
 typeof(Core._setsuper!)
 typeof(Core._structtype)
 typeof(Core._typebody!)
 typeof(Core._typevar)
 typeof(Core.apply_type)
 typeof(Core.arrayref)
 typeof(Core.arrayset)
 typeof(Core.arraysize)
 typeof(Core.const_arrayref)
 typeof(Core.sizeof)
 typeof(Core.svec)
 typeof(applicable)
 typeof(fieldtype)
 typeof(getfield)
 typeof(ifelse)
 typeof(invoke)
 typeof(isa)
 typeof(isdefined)
 typeof(nfields)
 typeof(setfield!)
 typeof(throw)
 typeof(tuple)
 typeof(typeassert)
 typeof(typeof)
adkabo commented 2 years ago

It's unfortunate that getindex(3) is already taken (returns 3).