Skip to content

Commit

Permalink
more leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Nov 4, 2024
1 parent e4b98d3 commit 64a6e22
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6' # Replace this with the minimum Julia version that your package supports.
- '1.10' # Replace this with the minimum Julia version that your package supports.
- '1' # automatically expands to the latest stable 1.x release of Julia
- 'nightly'
os:
Expand Down
1 change: 1 addition & 0 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ The following types instead are explicitly marked as leaves in Functors.jl:
- `Number`.
- `AbstractArray{<:Number}`, except for the wrappers `Transpose`, `Adjoint`, and `PermutedDimsArray`.
- `AbstractRNG`.
- `AbstractString`, `AbstractChar`, `AbstractPattern`, `AbstractMatch`.

This is because in typical application the internals of these are abstracted away and it is not desirable to traverse them.

Expand Down
4 changes: 4 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

@leaf Number
@leaf AbstractArray{<:Number}
@leaf AbstractString
@leaf AbstractChar
@leaf AbstractMatch
@leaf AbstractPattern
@leaf AbstractRNG

###
Expand Down
20 changes: 18 additions & 2 deletions test/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,28 @@ end
@test collect(x) isa Vector{<:Tuple{Complex, Complex}}
end

@testset "AbstractString is not leaf" begin
@testset "AbstractString is leaf" begin
struct DummyString <: AbstractString
str::String
end
s = DummyString("hello")
@test !Functors.isleaf(s)
@test Functors.isleaf(s)
end
@testset "AbstractPattern is leaf" begin
struct DummyPattern <: AbstractPattern
pat::Regex
end
p = DummyPattern(r"\d+")
@test Functors.isleaf(p)
@test Functors.isleaf(r"\d+")
end
@testset "AbstractChar is leaf" begin
struct DummyChar <: AbstractChar
ch::Char
end
c = DummyChar('a')
@test Functors.isleaf(c)
@test Functors.isleaf('a')
end

@testset "AbstractDict is functor" begin
Expand Down

0 comments on commit 64a6e22

Please sign in to comment.