Skip to content

Commit

Permalink
rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Oct 21, 2024
1 parent 1b4ac0f commit 66c3893
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions src/Functors.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
module Functors

export @functor, @flexiblefunctor, fmap, fmapstructure, fcollect, execute, fleaves,
using ConstructionBase: constructorof

export @leaf, @functor, @flexiblefunctor,
fmap, fmapstructure, fcollect, execute, fleaves,
fmap_with_path, fmapstructure_with_path,
KeyPath, getkeypath, haskeypath, setkeypath!
using ConstructionBase: constructorof


include("functor.jl")
include("keypath.jl")
Expand Down
2 changes: 0 additions & 2 deletions src/functor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ macro leaf(T)
:($Functors.functor(::Type{<:$(esc(T))}, x) = ($Functors.NoChildren(), _ -> x))
end

# @leaf Any # every type is a leaf by default

# Default functor
function functor(T, x)
names = fieldnames(T)
Expand Down
8 changes: 5 additions & 3 deletions test/basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ end
end

@testset "Self-referencing types" begin
@test fmap(identity, Base.ImmutableDict(:a => 42)) == Base.ImmutableDict(:a => 42)
# https://github.com/FluxML/Functors.jl/pull/72/
@test_broken fmap(identity, Base.ImmutableDict(:a => 42)) == Base.ImmutableDict(:a => 42)
end

@testset "functor(typeof(x), y) from @functor" begin
Expand Down Expand Up @@ -352,11 +353,12 @@ end
Functors.@leaf B
b = B(1)
children, re = Functors.functor(b)
@test re(children) === b

a = LeafType(1)
children, re = Functors.functor(a)
@test children == Functors.NoChildren()
@test re(children) === b
@test children == Functors.NoChildren()
@test re(children) === a
end

@testset "IterateWalk" begin
Expand Down

0 comments on commit 66c3893

Please sign in to comment.