Skip to content

Commit

Permalink
all Types are leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Nov 7, 2024
1 parent 8bb69eb commit 031ce60
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Functors"
uuid = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
authors = ["Mike J Innes <[email protected]>"]
version = "0.5.0"
version = "0.5.1"

[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
Expand Down
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
1 change: 1 addition & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
### Opt-Out
###

@leaf Type
@leaf Number
@leaf AbstractArray{<:Number}
@leaf AbstractString
Expand Down
9 changes: 8 additions & 1 deletion test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,11 @@ end
@test od2 isa OrderedDict
@test od2[1] == 2
@test od2[2] == 4
end
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

0 comments on commit 031ce60

Please sign in to comment.