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

adjoin function for Traversals #187

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

MoritzR
Copy link

@MoritzR MoritzR commented Dec 9, 2022

This adds an adjoin function for Traversals, that combines two Traversals into one.

const adjoin = <S, A>(traversalA: Traversal<S, A>, traversalB: Traversal<S, A>): Traversal<S, A> => ...

I could only do that by more or less translating the version from the haskell lens library.
For this reason the partsOf and product functions also come with it.

I was not sure how to best traverse the tuple type returned by product. I added a new Traversable instance for the readonly [A, A] type, though it doesn't look like that's the correct way to build that traverse function. Let me know what a better approach for this is.

This is mostly a translation from adjoin from the haskell lens library: https://hackage.haskell.org/package/lens-5.2/docs/Control-Lens-Unsound.html#v:adjoin

TraversableHomogeneousTuple was added as a way to safely traverse the tuple type that `lensProduct` produces.
An alternative way should be to use the array Traversable, but that requires casting in order for typescript to accept that.
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.

1 participant