Skip to content

Commit eafa78f

Browse files
docs
1 parent 6355bcd commit eafa78f

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

Project.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,16 @@ version = "0.4.4"
55

66
[deps]
77
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"
8-
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
98
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
109

1110
[compat]
1211
ConstructionBase = "1.4"
13-
Documenter = "0.27"
1412
julia = "1.6"
1513

1614
[extras]
17-
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
1815
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1916
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2017
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
2118

2219
[targets]
23-
test = ["Test", "Documenter", "StaticArrays", "Zygote"]
20+
test = ["Test", "StaticArrays", "Zygote"]

docs/src/index.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ For large models it can be cumbersome or inefficient to work with parameters as
88

99
## Basic Usage and Implementation
1010

11-
When one marks a structure as [`@functor`](@ref) it means that Functors.jl is allowed to look into the fields of the instances of the struct and modify them. This is achieved through [`Functors.fmap`](@ref).
11+
By default, julia types are marked as [`@functor`](@ref)s, meaning that Functors.jl is allowed to look into the fields of the instances of the struct and modify them. This is achieved through [`Functors.fmap`](@ref).
1212

13-
The workhorse of fmap is actually a lower level function, functor:
13+
The workhorse of `fmap` is actually a lower level function, functor:
1414

1515
```julia-repl
1616
julia> using Functors
@@ -20,8 +20,6 @@ julia> struct Foo
2020
y
2121
end
2222
23-
julia> @functor Foo
24-
2523
julia> foo = Foo(1, [1, 2, 3]) # notice all the elements are integers
2624
2725
julia> xs, re = Functors.functor(foo)
@@ -50,12 +48,17 @@ julia> fmap(float, model)
5048
Baz(1.0, 2)
5149
```
5250

53-
Any field not in the list will be passed through as-is during reconstruction. This is done by invoking the default constructor, so structs that define custom inner constructors are expected to provide one that acts like the default.
51+
Any field not in the list will be passed through as-is during reconstruction. This is done by invoking the default constructor accepting all fields as arguments, so structs that define custom inner constructors are expected to provide one that acts like the default.
5452

55-
## Appropriate Use
53+
The use of `@functor` with no fields argument as in `@functor Baz` is equivalent to `@functor Baz fieldnames(Baz)`
54+
and also equivalent to avoiding `@functor` altogether.
55+
56+
Using [`@leaf`](@ref) instead of [`@functor`](@ref) will prevent the fields of a struct from being traversed.
5657

57-
!!! warning "Not everything should be a functor!"
58-
Due to its generic nature it is very attractive to mark several structures as [`@functor`](@ref) when it may not be quite safe to do so.
58+
!!! warning "Change to opt-out behaviour in v0.5"
59+
Previous releases of functors, up to v0.4, used an opt-in behaviour where structs were not functors unless marked with `@functor`. This was changed in v0.5 to an opt-out behaviour where structs are functors unless marked with `@leaf`.
60+
61+
## Appropriate Use
5962

6063
Typically, since any function `f` is applied to the leaves of the tree, but it is possible for some functions to require dispatching on the specific type of the fields causing some methods to be missed entirely.
6164

src/Functors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ this can be restricted be restructed by providing a tuple of field names.
4040
```jldoctest
4141
julia> struct Foo; x; y; end
4242
43-
julia> @functor Foo
44-
4543
julia> Functors.children(Foo(1,2))
4644
(x = 1, y = 2)
4745
@@ -50,6 +48,8 @@ julia> _, re = Functors.functor(Foo(1,2));
5048
julia> re((10, 20))
5149
Foo(10, 20)
5250
51+
julia> @functor Foo # same as before, nothing changes
52+
5353
julia> struct TwoThirds a; b; c; end
5454
5555
julia> @functor TwoThirds (a, c)

test/runtests.jl

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,7 @@ using LinearAlgebra
44
using StaticArrays
55

66
@testset "Functors.jl" begin
7-
87
include("basics.jl")
98
include("base.jl")
109
include("flexiblefunctors.jl")
11-
12-
# if VERSION >= v"1.7"
13-
# @warn "skipping doctests, on Julia $VERSION"
14-
# else
15-
# using Documenter
16-
# @testset "doctests" begin
17-
# DocMeta.setdocmeta!(Functors, :DocTestSetup, :(using Functors); recursive=true)
18-
# doctest(Functors, manual=true)
19-
# end
20-
# end
2110
end

0 commit comments

Comments
 (0)