Skip to content

Instantly share code, notes, and snippets.

@thautwarm
Created May 25, 2022 01:42
Show Gist options
  • Save thautwarm/3db0de83efd8dfd0ab439cba80158b11 to your computer and use it in GitHub Desktop.
Save thautwarm/3db0de83efd8dfd0ab439cba80158b11 to your computer and use it in GitHub Desktop.
forward_def!
using MLStyle: @switch
macro forward_def!(self_ann, expr, methods...)
@switch self_ann begin
@case :($self :: $t_base{$(t_args...)})
@case :($self :: $t_base) && let t_args = [] end
end
t = if !isempty(t_args)
:($t_base{$(t_args...)})
else
t_base
end
block = []
for meth in methods
push!(block, :($Base.@inline $meth($self::$t, args...;kwargs...) where {$(t_args...)} = $meth($expr, args...; kwargs...)))
end
esc(Expr(:block, block...))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment