Skip to content

Commit

Permalink
tweak NamedTuple operations to be more type-stable
Browse files Browse the repository at this point in the history
  • Loading branch information
aplavin committed Jan 17, 2025
1 parent 87a4c61 commit c3b135c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/optics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,9 @@ function (l::PropertyLens{field})(obj) where {field}
getproperty(obj, field)
end

@inline set(obj, l::PropertyLens{field}, val) where {field} = setproperties(obj, (; field => val))
@inline set(obj, l::PropertyLens{field}, val) where {field} = setproperties(obj, NamedTuple{(field,)}((val,)))
@inline delete(obj::NamedTuple, l::PropertyLens{field}) where {field} = Base.structdiff(obj, NamedTuple{(field,)})
@inline insert(obj::NamedTuple, l::PropertyLens{field}, val) where {field} = (; obj..., (;field => val)...)
@inline insert(obj::NamedTuple{KS}, l::PropertyLens{field}, val) where {KS, field} = NamedTuple{(KS..., field)}((values(obj)..., val))

@inline set(obj::Tuple, l::PropertyLens{field}, val) where {field} = set(obj, IndexLens(field), val)
@inline delete(obj::Tuple, l::PropertyLens{field}) where {field} = delete(obj, IndexLens(field))
Expand Down

0 comments on commit c3b135c

Please sign in to comment.