You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(::_GetAll{N})(_) where {N} =error("Too many chained optics: $N is not supported for now. See also https://github.com/JuliaObjects/Accessors.jl/pull/64.")
43
55
@@ -74,3 +86,69 @@ end
74
86
for i in2:10
75
87
eval(_generate_getall(i))
76
88
end
89
+
90
+
91
+
92
+
struct _SetAll{N} end
93
+
94
+
# don't review SetAll{2} and {3}
95
+
function (::_SetAll{2})(obj, optic, vs)
96
+
(f1, f2) =deopcompose(optic)
97
+
98
+
ins_old =getall(obj, f1)
99
+
vss =reduce(ins_old; init=((), vs)) do (acc, vs), o
100
+
vs_cur, vs_rest =_split_n(vs, getall(o, f2))
101
+
(acc..., vs_cur), vs_rest
102
+
end|> first
103
+
ins =map(ins_old, vss) do o, vs_cur
104
+
setall(o, f2, vs_cur)
105
+
end
106
+
setall(obj, f1, ins)
107
+
end
108
+
109
+
function (::_SetAll{3})(obj, optic, vs)
110
+
(f1, f2, f3) =deopcompose(optic)
111
+
112
+
ins_old_1 =getall(obj, f1)
113
+
vss_1 =_split_getall(ins_old_1, f3 ∘ f2, vs)
114
+
ins_1 =map(ins_old_1, vss_1) do o, vs_cur
115
+
ins_old_2 =getall(o, f2)
116
+
vss_2 =_split_getall(ins_old_2, f3, vs_cur)
117
+
ins_2 =map(ins_old_2, vss_2) do o, vs_cur
118
+
setall(o, f3, vs_cur)
119
+
end
120
+
setall(o, f2, ins_2)
121
+
end
122
+
setall(obj, f1, ins_1)
123
+
end
124
+
125
+
# only review SetAll{4} and helpers below
126
+
function (::_SetAll{4})(o, optic, vs)
127
+
(f1, f2, f3, f4) =deopcompose(optic)
128
+
129
+
ins_old_1 =getall(o, f1)
130
+
vss_1 =_split_getall(ins_old_1, f4 ∘ f3 ∘ f2, vs)
131
+
ins_1 =map(ins_old_1, vss_1) do o, vs_cur
132
+
ins_old_2 =getall(o, f2)
133
+
vss_2 =_split_getall(ins_old_2, f4 ∘ f3, vs_cur)
134
+
ins_2 =map(ins_old_2, vss_2) do o, vs_cur
135
+
ins_old_3 =getall(o, f3)
136
+
vss_3 =_split_getall(ins_old_3, f4, vs_cur)
137
+
ins_3 =map(ins_old_3, vss_3) do o, vs_cur
138
+
setall(o, f4, vs_cur)
139
+
end
140
+
setall(o, f3, ins_3)
141
+
end
142
+
setall(o, f2, ins_2)
143
+
end
144
+
setall(o, f1, ins_1)
145
+
end
146
+
147
+
# split a into two parts: b-sized front and remaining
148
+
_split_n(a::NTuple{Na, Any}, b::NTuple{Nb, Any}) where {Na, Nb} =ntuple(i -> a[i], Nb), ntuple(i -> a[Nb + i], Na - Nb)
149
+
150
+
# split vs into parts sized according to getall(o, f)
151
+
_split_getall(ins_old, f, vs) =foldl(ins_old; init=((), vs)) do (acc, vs_), o
0 commit comments