Skip to content

Commit

Permalink
add optic negation
Browse files Browse the repository at this point in the history
same as how functions work
  • Loading branch information
aplavin committed Jan 5, 2024
1 parent 8634e59 commit d0b2ccc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/optics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ Broadcast.broadcastable(
o::Union{PropertyLens,IndexLens,DynamicIndexLens,Elements,Properties,If,Recursive}
) = Ref(o)

Base.:(!)(f::Union{PropertyLens,IndexLens,DynamicIndexLens}) = (!) f


function make_salt(s64::UInt64)::UInt
# used for faster hashes. See https://github.com/jw3126/Setfield.jl/pull/162
Expand Down
4 changes: 4 additions & 0 deletions test/test_functionlenses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ end
@test set((a=3, b=4), norm, 10) === (a=6., b=8.)
test_getset_laws(norm, (3, 4), 10, 12)
test_getset_laws(Base.splat(hypot), (3, 4), 10, 12)

test_getset_laws(!(@optic _.a), (a=true,), false, true)
test_getset_laws(!(@optic _[1]), (a=true,), false, true)
test_getset_laws(!(@optic _[end]), (a=true,), false, true)
end

@testset "dates" begin
Expand Down

0 comments on commit d0b2ccc

Please sign in to comment.