jw3126 / Setfield.jl

Update deeply nested immutable structs.
Other
167 stars 17 forks source link

Setproperty #12

Closed jw3126 closed 6 years ago

jw3126 commented 6 years ago

@tkf

+# https://github.com/tkf/Reconstructables.jl#how-to-use-type-parameters
+struct B{T, X, Y}
+    x::X
+    y::Y
+    B{T}(x::X, y::Y = 2) where {T, X, Y} = new{T, X, Y}(x, y)
+end
+Setfield.constructor_of(::Type{<: B{T}}) where T = B{T}
+
+@testset "type change during @set" begin
+    obj = B{1}(2,3)
+    obj2 = @set obj.y = :three
+    @test obj2 === B{1}(2, :three)
+end

works now!

codecov-io commented 6 years ago

Codecov Report

Merging #12 into master will increase coverage by 0.33%. The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #12      +/-   ##
==========================================
+ Coverage   87.27%   87.61%   +0.33%     
==========================================
  Files           3        3              
  Lines         110      113       +3     
==========================================
+ Hits           96       99       +3     
  Misses         14       14
Impacted Files Coverage Δ
src/Setfield.jl 100% <ø> (ø) :arrow_up:
src/sugar.jl 89.65% <100%> (ø) :arrow_up:
src/lens.jl 84.9% <92.85%> (+0.9%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 41afdcf...4788d31. Read the comment docs.