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 .entries(), .keys(), .values() record traversals #81

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

akheron
Copy link
Owner

@akheron akheron commented Apr 12, 2021

No description provided.

@cowboyd
Copy link

cowboyd commented Apr 14, 2021

Cool! I have some questions with this API, what would be the best way to do the following?

a. add an entry?
b. remove an entry?
c. remove a key and have it remove the entry?
d. remove a value and have it remove the entry?

@akheron
Copy link
Owner Author

akheron commented Apr 14, 2021

Unfortunately, traversals don’t allow that kind of stuff in general. Introducing something like RemovableTraversal could make sense, though, especially if it would allow returning a special “remove me” value from modify to remove the element at focus.

@akheron
Copy link
Owner Author

akheron commented Apr 14, 2021

Also, typescript seems to have really hard time to type check certain things with this pr’s modifications, so I’m not sure if this can be merged at all.

@akheron
Copy link
Owner Author

akheron commented Apr 14, 2021

One more thing: If you’re using optics from a JavaScript project (instead of TypeScript), I highly recommend https://github.com/calmm-js/partial.lenses. It’s much more feature complete than optics-ts and supports stuff you mentioned. It’s much harder to implement those in optics-ts because the restrictions imposed by the type system need to be taken into account.

@akheron akheron changed the title Add .entries(), .keys(), .values() object traversals Add .entries(), .keys(), .values() record traversals Apr 14, 2021
@cowboyd
Copy link

cowboyd commented Apr 15, 2021

That's good to know. I was able to use optics-ts to remove and add from traversals on runkit which is, of course, untyped. So it is at least possible, but I don't know if what I was doing was a hack, and how it might work with the type system. I don't know if you had a chance to read it here https://runkit.com/cowboyd/optics-ts-record-traversal

I will have a look at partial.lenses

@cowboyd
Copy link

cowboyd commented Jul 2, 2021

@akheron

Also, typescript seems to have really hard time to type check certain things with this pr’s modifications, so I’m not sure if this can be merged at all.

What is missing from TypeScript to be able to do this? We're definitely not using JavaScript, so this library seems like our best hope.

Unfortunately, traversals don’t allow that kind of stuff in general. Introducing something like RemovableTraversal could make sense, though, especially if it would allow returning a special “remove me” value from modify to remove the element at focus.

What would that API look like?

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 7 Code Smells

No Coverage information No Coverage information
10.1% 10.1% Duplication

@kevinschaich
Copy link

Are there any blockers from merging and releasing this?

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.

3 participants