From 97a3e89689e14c7a0b1ed6153e28fca720a6238f Mon Sep 17 00:00:00 2001 From: Brad Carman Date: Thu, 27 Oct 2022 13:27:09 -0400 Subject: [PATCH] code and test --- src/lens.jl | 4 ++++ test/test_core.jl | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/lens.jl b/src/lens.jl index cbd4220..865b5b2 100644 --- a/src/lens.jl +++ b/src/lens.jl @@ -259,3 +259,7 @@ struct FunctionLens{f} <: Lens end FunctionLens(f) = FunctionLens{f}() get(obj, ::FunctionLens{f}) where f = f(obj) + + +Base.hasproperty(obj, l::Setfield.ComposedLens) = hasproperty(obj, l.outer) +Base.hasproperty(obj, l::PropertyLens{f}) where f = hasproperty(obj, f) \ No newline at end of file diff --git a/test/test_core.jl b/test/test_core.jl index 867a259..3b87d56 100644 --- a/test/test_core.jl +++ b/test/test_core.jl @@ -518,4 +518,14 @@ end @test @lens(_.x[1, :].$(fancy(name, "✨"))) == @lens(_.x[1, :].fancy_a✨) end +@testset "hasproperty" begin + obj = (x=1,) + + l1 = @lens _.x + l2 = @lens _.y + + @test hasproperty(obj, l1) + @test !hasproperty(obj, l2) +end + end