Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add == definition of ComposedOptic and IndexLens from Setfield #146

Closed
wants to merge 6 commits into from
Closed

Conversation

sunxd3
Copy link

@sunxd3 sunxd3 commented Mar 22, 2024

Fix #144
Pretty much copy and paste

@sunxd3
Copy link
Author

sunxd3 commented Mar 22, 2024

Looks like Aqua is not happy with the == for CompsedOptic, which is essentially defining for ComposedFunction. Not sure what to do here.

src/optics.jl Show resolved Hide resolved
@aplavin
Copy link
Member

aplavin commented Mar 22, 2024

Also makes sense to add these equality methods to other optics defined in the file: eg DynamicIndexLens and Recursive.

test/test_core.jl Outdated Show resolved Hide resolved
src/optics.jl Outdated Show resolved Hide resolved
test/test_core.jl Outdated Show resolved Hide resolved
test/test_core.jl Outdated Show resolved Hide resolved
sunxd3 and others added 2 commits March 23, 2024 09:37
Co-authored-by: Jan Weidner <[email protected]>
Co-authored-by: Jan Weidner <[email protected]>
Comment on lines +226 to +236
# equality with non-equal range types (Setfield #165)
for (l1, l2) ∈ [
@optic(_[1:10]) => @optic(_[Base.OneTo(10)]),
@optic(_.a[1:10]) => @optic(_.a[Base.OneTo(10)]),
@optic(_.a.b[1:10]) => @optic(_.a.b[Base.OneTo(10)]),
@optic(_.a[Base.StepRange(1, 1, 5)].b[1:10]) => @optic(_.a[1:5].b[Base.OneTo(10)]),
@optic(_.a.b[1:3]) => @optic(_.a.b[[1, 2, 3]]),
]
@test l1 == l2
@test hash(l1) == hash(l2)
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== for ComposedFunctions are === by https://github.com/JuliaLang/julia/blob/63e365feb8692b9d7cb5298954c26ab7af268171/base/Base.jl#L208, which means other than the first tuple (tests between IndexLens), all will be false because they are not egal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe create a question/issue for Julia itself?

@sunxd3
Copy link
Author

sunxd3 commented Mar 23, 2024

Also I just realize adding equality for DynamicIndexLens is tricky, because the f field is anonymous function like collection -> firstindex(collection), which makes equality tests generally impossible.
Recursive is similar as Descent can be anonymous function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

== not defined for IndexLens
3 participants