Skip to content

adjoin function for Traversals#187

Open
MoritzR wants to merge 3 commits into
gcanti:masterfrom
MoritzR:master
Open

adjoin function for Traversals#187
MoritzR wants to merge 3 commits into
gcanti:masterfrom
MoritzR:master

Conversation

@MoritzR

@MoritzR MoritzR commented Dec 9, 2022

Copy link
Copy Markdown

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