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

Compose producing unexpected values #38

Open
christopherjmblack opened this issue Jul 11, 2022 · 1 comment
Open

Compose producing unexpected values #38

christopherjmblack opened this issue Jul 11, 2022 · 1 comment

Comments

@christopherjmblack
Copy link

The following two snippets produce different results:

The following appears to me to be correct:

lens.Each().Parts().F(sum).get()([1,2,3]) # returns 6

Whereas I think this is a bug:

(lens.Each() & lens.Parts().F(sum)).get()([1,2,3]) # returns 1

I'm using python-lenses 1.1.0, running in python 3.9.13.

@ingolemo
Copy link
Owner

Just to narrow down the example; the difference is between lens.Each().Parts() and lens.Each() & lens.Parts().

This is really an unfortunate api by me. I tried to make lens.Parts work more or less the same way as the other methods so that you could just tack it onto the end of a method chain and it would do what you want, but as you can see this breaks composition. In the underlying implementation the first one is really doing something like parts(each()) & f(sum) while the second is roughly each() & parts(identity()) & f(sum).

Possible solutions:

  1. Change the syntax to be more representative of the underlying structure. lens.Parts would now take an argument which is the lens that you want it to apply to. The example would have to be written as lens.Parts(lens.Each()).F(sum).get()([1,2,3]). This would break existing code.
  2. Document the problem and tell people to be careful mixing lens.Parts with composition.

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

No branches or pull requests

2 participants