Skip to content

Commit 68567fd

Browse files
committed
fix itr for fieldless objects
1 parent 765d9eb commit 68567fd

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/optics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function mapproperties(f, obj::O, handler=Construct(), itr=nothing) where O
269269
# TODO move this helper elsewhere?
270270
pnames = propertynames(obj)
271271
if isempty(pnames)
272-
return obj
272+
return _maybeitr(obj, itr)
273273
else
274274
# TODO: this is too slow
275275
new_props, itr = reduce(pnames; init=((), itr)) do (vals, itr), p
@@ -334,7 +334,7 @@ $EXPERIMENTAL
334334
fnames = fieldnames(O)
335335
ctr = _constructor(H(), O)
336336
if isempty(fnames)
337-
:(return obj)
337+
:(return _maybeitr(obj, itr))
338338
else
339339
prop_args = map(fn -> :(getfield(obj, $(QuoteNode(fn)))), fnames)
340340
prop_exp = Expr(:tuple, prop_args...)

test/test_queries.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Accessors, Test, BenchmarkTools
22

3-
obj = (7, (a=17.0, b=2.0f0), ("3", 4, 5.0), (x=6.0,), )
3+
obj = (7, (a=17.0, b=2.0f0), ("3", 4, 5.0), (x=6.0,), [1])
44
vals = (1.0, 2.0, 3.0, 4.0)
55

66
# Fields is the default
@@ -24,7 +24,7 @@ println("set")
2424
@btime Accessors.set($obj, $slowlens, $vals)
2525
@test Accessors.set(obj, lens, vals) ==
2626
Accessors.set(obj, lens, vals) ==
27-
(7, (a=1.0, b=2.0f0), ("3", 4, 5.0), (x=2.0,), )
27+
(7, (a=1.0, b=2.0f0), ("3", 4, 5.0), (x=2.0,), [1])
2828

2929
# using ProfileView
3030
# @profview for i in 1:1000000 Accessors.set(obj, lens, vals) end

0 commit comments

Comments
 (0)