Skip to content

Commit 3903a66

Browse files
committed
add constructorof for PropertyLens
1 parent 18d8625 commit 3903a66

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/optics.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ The second constructor may not be type stable when `fieldname` is not a constant
392392
"""
393393
@inline PropertyLens(fieldname) = PropertyLens{fieldname}()
394394

395+
ConstructionBase.constructorof(::Type{PropertyLens{P}}) where {P} = PropertyLens{P}
396+
395397
function (l::PropertyLens{field})(obj) where {field}
396398
getproperty(obj, field)
397399
end

test/test_optics.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,14 @@ end
9393
@inferred modify(x -> 0, arr, @optic _ |> Elements() |> If(iseven))
9494
end
9595

96-
@testset "convenience constructors" begin
96+
@testset "constructors" begin
9797
@test IndexLens(1, 2, 3) === IndexLens((1, 2, 3))
9898
@test PropertyLens(:a) === PropertyLens{:a}()
99+
100+
f = PropertyLens(:a)
101+
@test constructorof(typeof(f))(Accessors.getfields(f)...) === f
102+
f = IndexLens(1, 2, 3)
103+
@test constructorof(typeof(f))(Accessors.getfields(f)...) === f
99104
end
100105

101106
@testset "broadcasting" begin

0 commit comments

Comments
 (0)