diff --git a/src/Functors.jl b/src/Functors.jl index 599ee72..e332d73 100644 --- a/src/Functors.jl +++ b/src/Functors.jl @@ -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") diff --git a/src/functor.jl b/src/functor.jl index ca6b995..ca426d7 100644 --- a/src/functor.jl +++ b/src/functor.jl @@ -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) diff --git a/test/basics.jl b/test/basics.jl index ced07a1..e8d326f 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -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 @@ -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