From 031ce60743ee4890c507c8b8ab6fdb866c91e461 Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 6 Nov 2024 20:54:43 -0500 Subject: [PATCH] all Types are leaf --- Project.toml | 2 +- docs/src/index.md | 1 + src/base.jl | 1 + test/base.jl | 9 ++++++++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 63eecba..888c22b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Functors" uuid = "d9f16b24-f501-4c13-a1f2-28368ffc5196" authors = ["Mike J Innes "] -version = "0.5.0" +version = "0.5.1" [deps] Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" diff --git a/docs/src/index.md b/docs/src/index.md index c4dc636..9e5027b 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -62,6 +62,7 @@ Using [`@leaf`](@ref) instead of [`@functor`](@ref) will prevent the fields of a By default all composite types in are functors and can be traversed, unless marked with [`@leaf`](@ref). The following types instead are explicitly marked as leaves in Functors.jl: +- `Type` - `Number`. - `AbstractArray{<:Number}`, except for the wrappers `Transpose`, `Adjoint`, and `PermutedDimsArray`. - `AbstractRNG`. diff --git a/src/base.jl b/src/base.jl index b112c0d..7b8a3ad 100644 --- a/src/base.jl +++ b/src/base.jl @@ -2,6 +2,7 @@ ### Opt-Out ### +@leaf Type @leaf Number @leaf AbstractArray{<:Number} @leaf AbstractString diff --git a/test/base.jl b/test/base.jl index 5fd6466..918401e 100644 --- a/test/base.jl +++ b/test/base.jl @@ -211,4 +211,11 @@ end @test od2 isa OrderedDict @test od2[1] == 2 @test od2[2] == 4 -end \ No newline at end of file +end + +@testset "Types are leaves" begin + @test Functors.isleaf(Int) + @test Functors.isleaf(Array) + @test fmap(identity, (1,Int,Ref,Array,5)) == (1,Int,Ref,Array,5) +end +