Skip to content

Commit a7ce0f2

Browse files
committed
Fix missing docs and cross-references
* make the docs of @functor render in the manual * fix cross-references within the docs * update .gitignore
1 parent 0cf7942 commit a7ce0f2

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
/dev/
33
Manifest.toml
4+
build
5+
.vscode

src/Functors.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Returns a tuple containing, first, a `NamedTuple` of the children of `x`
1919
This controls the behaviour of [`fmap`](@ref).
2020
2121
Methods should be added to `functor(::Type{T}, x)` for custom types,
22-
usually using the macro [@functor](@ref).
22+
usually using the macro [`@functor`](@ref).
2323
"""
2424
functor
2525

@@ -32,7 +32,7 @@ Adds methods to [`functor`](@ref) allowing recursion into objects of type `T`,
3232
and reconstruction. Assumes that `T` has a constructor accepting all of its fields,
3333
which is true unless you have provided an inner constructor which does not.
3434
35-
By default all fields of `T` are considered [children](@ref);
35+
By default all fields of `T` are considered [`children`](@ref);
3636
this can be restricted be restructed by providing a tuple of field names.
3737
3838
# Examples

src/functor.jl

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,47 @@ function functorm(T, fs = nothing)
3030
:(makefunctor(@__MODULE__, $(esc(T)), $(fs...)))
3131
end
3232

33+
"""
34+
@functor T
35+
@functor T (x,)
36+
37+
Adds methods to [`functor`](@ref) allowing recursion into objects of type `T`,
38+
and reconstruction. Assumes that `T` has a constructor accepting all of its fields,
39+
which is true unless you have provided an inner constructor which does not.
40+
41+
By default all fields of `T` are considered [`children`](@ref);
42+
this can be restricted be restructed by providing a tuple of field names.
43+
44+
# Examples
45+
```jldoctest
46+
julia> struct Foo; x; y; end
47+
48+
julia> @functor Foo
49+
50+
julia> Functors.children(Foo(1,2))
51+
(x = 1, y = 2)
52+
53+
julia> _, re = Functors.functor(Foo(1,2));
54+
55+
julia> re((10, 20))
56+
Foo(10, 20)
57+
58+
julia> struct TwoThirds a; b; c; end
59+
60+
julia> @functor TwoThirds (a, c)
61+
62+
julia> ch2, re3 = Functors.functor(TwoThirds(10,20,30));
63+
64+
julia> ch2
65+
(a = 10, c = 30)
66+
67+
julia> re3(("ten", "thirty"))
68+
TwoThirds("ten", 20, "thirty")
69+
70+
julia> fmap(x -> 10x, TwoThirds(Foo(1,2), Foo(3,4), 56))
71+
TwoThirds(Foo(10, 20), Foo(3, 4), 560)
72+
```
73+
"""
3374
macro functor(args...)
3475
functorm(args...)
3576
end

0 commit comments

Comments
 (0)