From c43f2ea8c24c8be4913721aac30b7fe1502c1126 Mon Sep 17 00:00:00 2001 From: Carlo Lucibello Date: Tue, 22 Oct 2024 00:09:02 +0200 Subject: [PATCH] docs --- docs/src/index.md | 8 ++++---- src/Functors.jl | 2 +- src/base.jl | 2 +- src/walks.jl | 3 ++- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/docs/src/index.md b/docs/src/index.md index 4ed2a40..805e9bf 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -64,15 +64,15 @@ 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: -- `Number` -- `AbstractArray{<:Number}` -- `AbstractString` +- `Number`. +- `AbstractArray{<:Number}`, except for the wrappers `Transpose`, `Adjoint`, and `PermutedDimsArray`. +- `AbstractString`. This is because in typical application the internals of these are abstracted away and it is not desirable to traverse them. ## What if I get an error? -Since by default Funcotrs.jl tries to traverse most types e.g. when using [`fmap`](@ref), it is possible it fails in case the type has not an appropriate constructor. If use experience this issue, you have a few alternatives: +Since by default Functors.jl tries to traverse most types e.g. when using [`fmap`](@ref), it is possible it fails in case the type has not an appropriate constructor. If use experience this issue, you have a few alternatives: - Mark the type as a leaf using [`@leaf`](@ref) - Use the `@functor` macro to specify which fields to traverse. - Define an appropriate constructor for the type. diff --git a/src/Functors.jl b/src/Functors.jl index be39349..f99c665 100644 --- a/src/Functors.jl +++ b/src/Functors.jl @@ -26,7 +26,7 @@ include("base.jl") functor(typeof(x), x) Returns a tuple containing, first, a `NamedTuple` of the children of `x` -(typically its fields), and second, a reconstruction funciton. +(typically its fields), and second, a reconstruction function. This controls the behaviour of [`fmap`](@ref). Methods should be added to `functor(::Type{T}, x)` for custom types, diff --git a/src/base.jl b/src/base.jl index bc78f8e..c94916d 100644 --- a/src/base.jl +++ b/src/base.jl @@ -43,7 +43,7 @@ function functor(::Type{<:PermutedDimsArray{T,N,perm,iperm}}, x) where {T,N,perm (parent = _PermutedDimsArray(x, iperm),), y -> PermutedDimsArray(only(y), perm) end function functor(::Type{<:PermutedDimsArray{T,N,perm,iperm}}, x::PermutedDimsArray{Tx,N,perm,iperm}) where {T,Tx,N,perm,iperm} - (parent = parent(x),), y -> PermutedDimsArray(only(y), perm) # most common case, avoid wrapping wrice. + (parent = parent(x),), y -> PermutedDimsArray(only(y), perm) # most common case, avoid wrapping twice. end _PermutedDimsArray(x, iperm) = PermutedDimsArray(x, iperm) diff --git a/src/walks.jl b/src/walks.jl index 928cc3f..856b622 100644 --- a/src/walks.jl +++ b/src/walks.jl @@ -9,7 +9,8 @@ function check_lenghts(x, ys...) end _map(f, x::Dict, ys...) = Dict(k => f(v, (y[k] for y in ys)...) for (k, v) in x) -_map(f, x::D, ys...) where {D<:AbstractDict} = constructorof(D)(k => f(v, (y[k] for y in ys)...) for (k, v) in x) +_map(f, x::D, ys...) where {D<:AbstractDict} = + constructorof(D)(k => f(v, (y[k] for y in ys)...) for (k, v) in x) _values(x) = x _values(x::AbstractDict) = values(x)