Skip to content

Commit

Permalink
Replace ismutablestruct(x) with implements(::typeof(setproperty!), x)
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Jan 7, 2020
1 parent 9d439e2 commit 5ca893e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ end

pure(::typeof(setproperties!)) = NoBang.setproperties
possible(::typeof(setproperties!), obj, patch) =
ismutablestruct(obj) && _is_compatible_field_types(obj, patch)
implements(setproperty!, obj) && _is_compatible_field_types(obj, patch)

_is_compatible_field_types(::T, patch) where T =
all(n -> fieldtype(typeof(patch), n) <: fieldtype(T, n), keys(patch))
Expand Down
9 changes: 2 additions & 7 deletions src/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ implements(::Mutator, ::Type{<:ImmutableContainer}) = false
implements(::Mutator, ::Type{<:MaybeMutableContainer}) = true
implements(::Mutator, ::Type{<:AbstractString}) = false

"""
ismutablestruct(x)
`true` if `x` is mutable as a struct/object.
"""
ismutablestruct(x) = ismutablestruct(typeof(x))
Base.@pure ismutablestruct(T::DataType) = T.mutable
ismutablestruct(::Type{<:NamedTuple}) = false
implements(::typeof(setproperty!), T::DataType) = ismutablestruct(T)
implements(::typeof(setproperty!), ::Type{<:NamedTuple}) = false

# trymutate(::typeof(push!)) = push!!
# trymutate(::typeof(append!)) = append!!
Expand Down

0 comments on commit 5ca893e

Please sign in to comment.