Skip to content

Commit 81017f2

Browse files
cleanup
1 parent 40b77a8 commit 81017f2

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

src/functor.jl

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@ functor(::Type{<:AbstractArray}, x) = x, identity
1717
functor(::Type{<:AbstractArray{<:Number}}, x) = (), _ -> x
1818

1919
function makefunctor(m::Module, T, fs = fieldnames(T))
20-
if isempty(fs)
21-
@eval m begin
22-
$Functors.functor(::Type{<:$T}, x) = (), _ -> x
23-
end
24-
else
25-
yᵢ = 0
26-
escargs = map(fieldnames(T)) do f
27-
f in fs ? :(y[$(yᵢ += 1)]) : :(x.$f)
28-
end
29-
escfs = [:($f=x.$f) for f in fs]
30-
31-
@eval m begin
32-
$Functors.functor(::Type{<:$T}, x) = (;$(escfs...)), y -> $T($(escargs...))
33-
end
20+
yᵢ = 0
21+
escargs = map(fieldnames(T)) do f
22+
f in fs ? :(y[$(yᵢ += 1)]) : :(x.$f)
23+
end
24+
escfs = [:($f=x.$f) for f in fs]
25+
26+
@eval m begin
27+
$Functors.functor(::Type{<:$T}, x) = (;$(escfs...)), y -> $T($(escargs...))
3428
end
3529
end
3630

@@ -44,7 +38,7 @@ macro functor(args...)
4438
functorm(args...)
4539
end
4640

47-
isleaf(@nospecialize(x)) = children(x) === ()
41+
isleaf(@nospecialize(x)) = isempty(children(x))
4842

4943
children(x) = functor(x)[1]
5044

test/basics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ struct NoChild{T}; x::T; end
2323
has_children = Foo(1, 2)
2424
@test Functors.isleaf(no_children)
2525
@test !Functors.isleaf(has_children)
26-
@test Functors.children(no_children) == ()
26+
@test Functors.children(no_children) == (;)
2727
@test Functors.children(has_children) == (x=1, y=2)
2828
end
2929

0 commit comments

Comments
 (0)