Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Dec 7, 2022
1 parent 9986158 commit 84f5253
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@ functor(::Type{<:AbstractArray}, x) = x, identity
@leaf AbstractArray{<:Number}

function makefunctor(m::Module, T, fs = fieldnames(T))
if isempty(fs)
@eval m begin
$Functors.functor(::Type{<:$T}, x) = (), _ -> x
end
else
yᵢ = 0
escargs = map(fieldnames(T)) do f
f in fs ? :(y[$(yᵢ += 1)]) : :(x.$f)
end
escfs = [:($f=x.$f) for f in fs]

@eval m begin
$Functors.functor(::Type{<:$T}, x) = (;$(escfs...)), y -> $T($(escargs...))
end
yᵢ = 0
escargs = map(fieldnames(T)) do f
f in fs ? :(y[$(yᵢ += 1)]) : :(x.$f)
end
escfs = [:($f=x.$f) for f in fs]

@eval m begin
$Functors.functor(::Type{<:$T}, x) = (;$(escfs...)), y -> $T($(escargs...))
end
end

Expand Down

0 comments on commit 84f5253

Please sign in to comment.