Skip to content

Commit

Permalink
revisit leaves
Browse files Browse the repository at this point in the history
  • Loading branch information
CarloLucibello committed Nov 4, 2024
1 parent d4e5aea commit 3af3482
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ version = "0.4.12"
[deps]
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[compat]
Compat = "4.16"
ConstructionBase = "1.4"
LaTeXStrings = "1.4.0"
Measurements = "2"
OrderedCollections = "1.6"
Random = "1"
julia = "1.6"

[extras]
Expand Down
2 changes: 1 addition & 1 deletion docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ By default all composite types in are functors and can be traversed, unless mark
The following types instead are explicitly marked as leaves in Functors.jl:
- `Number`.
- `AbstractArray{<:Number}`, except for the wrappers `Transpose`, `Adjoint`, and `PermutedDimsArray`.
- `AbstractString`.
- `AbstractRNG`.

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

Expand Down
1 change: 1 addition & 0 deletions src/Functors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Functors
using Compat: @compat
using ConstructionBase: constructorof
using LinearAlgebra
using Random: AbstractRNG

export @leaf, @functor, @flexiblefunctor,
fmap, fmapstructure, fcollect, execute, fleaves,
Expand Down
2 changes: 1 addition & 1 deletion src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

@leaf Number
@leaf AbstractArray{<:Number}
@leaf AbstractString
@leaf AbstractRNG

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

@testset "AbstractString is leaf" begin
@testset "AbstractString is not leaf" begin
struct DummyString <: AbstractString
str::String
end
s = DummyString("hello")
@test Functors.isleaf(s)
@test !Functors.isleaf(s)
end

@testset "AbstractDict is functor" begin
Expand Down

0 comments on commit 3af3482

Please sign in to comment.