Skip to content

Commit c1c6b5c

Browse files
committed
more reorder
1 parent e528129 commit c1c6b5c

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/getsetall.jl

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ julia> getall(obj, @optic _ |> Elements() |> last)
2020
"""
2121
function getall end
2222

23+
# implementations for individual noncomposite optics
24+
2325
getall(obj::Union{Tuple, AbstractVector}, ::Elements) = obj
2426
getall(obj::Union{NamedTuple}, ::Elements) = values(obj)
2527
getall(obj::AbstractArray, ::Elements) = vec(obj)
@@ -38,8 +40,10 @@ setall(obj, o::If, vs) = error("Not supported")
3840
setall(obj, o, vs) = set(obj, o, only(vs))
3941

4042

41-
# A straightforward recursive implementation of getall and setall don't actually infer,
42-
# see https://github.com/JuliaObjects/Accessors.jl/pull/64.
43+
# implementations for composite optics
44+
45+
# A straightforward recursive approach doesn't actually infer,
46+
# see https://github.com/JuliaObjects/Accessors.jl/pull/64 and https://github.com/JuliaObjects/Accessors.jl/pull/68.
4347
# Instead, we need to generate separate functions for each recursion level.
4448

4549
function getall(obj, optic::ComposedFunction)
@@ -80,6 +84,8 @@ for i in 2:10
8084
end
8185

8286

87+
# helper functions
88+
8389
_concat(a::Tuple, b::Tuple) = (a..., b...)
8490
_concat(a::Tuple, b::AbstractVector) = vcat(collect(a), b)
8591
_concat(a::AbstractVector, b::Tuple) = vcat(a, collect(b))
@@ -93,10 +99,6 @@ _reduce_concat(xs::AbstractVector{<:AbstractVector}) = reduce(vcat, xs)
9399
_staticlength(::NTuple{N, <:Any}) where {N} = Val(N)
94100
_staticlength(x::AbstractVector) = length(x)
95101

96-
_val(N::Int) = N
97-
_val(::Val{N}) where {N} = N
98-
99-
100102
getall_lengths(obj, optic, ::Val{1}) = _staticlength(getall(obj, optic))
101103
for i in 2:10
102104
@eval function getall_lengths(obj, optic, ::Val{$i})
@@ -107,12 +109,10 @@ for i in 2:10
107109
end
108110
end
109111

110-
111112
nestedsum(ls::Int) = ls
112113
nestedsum(ls::Val) = ls
113114
nestedsum(ls::Tuple) = sum(_val nestedsum, ls)
114115

115-
116116
to_nested_shape(vs, ::Val{LS}, ::Val{1}) where {LS} = (@assert length(vs) == _val(LS); vs)
117117
for i in 2:10
118118
@eval @generated function to_nested_shape(vs, ls::Val{LS}, ::Val{$i}) where {LS}
@@ -129,3 +129,6 @@ for i in 2:10
129129
:( ($(subs...),) )
130130
end
131131
end
132+
133+
_val(N::Int) = N
134+
_val(::Val{N}) where {N} = N

0 commit comments

Comments
 (0)