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

interop with Diff #3

Open
mstksg opened this issue Mar 6, 2018 · 2 comments
Open

interop with Diff #3

mstksg opened this issue Mar 6, 2018 · 2 comments

Comments

@mstksg
Copy link

mstksg commented Mar 6, 2018

Hi! Thanks for the great library.

Was wondering if there was any meaningful way to "merge" two [Diff a]'s into a [Hunk a], such that:

xs, ys, zs :: [A]

xsys, xszs :: [Diff A]
xsys = getDiff xs ys
xszs = getDiff xs zs

xsyszs :: [Hunk a]
xsyszs = diff3 ys xs zs
-- or
xsyszs = mergeDiffs xsys xszs

Where if you diff two lists from the same original lists and merge the resulting diffs, you get what you would if you had originally diff3'd all three together at the same time.

I see that toHunk in the source appears to have the right type signature -- I'm not exactly sure what it does, but does it give the behavior I am thinking of?

@ocharles
Copy link
Owner

ocharles commented Mar 6, 2018

I don't think toHunk is quite what you want - note that it's called here only in the degenerate cases where one of the lists is empty. Can I ask what your use case is?

@mstksg
Copy link
Author

mstksg commented Mar 6, 2018

Actually I just realized that what I'm thinking about is exactly step from the implementation of diff3 :)

My particular use case is for working with "patches" as standalone data types, where a [Diff A] is a patch that can be applied to an [A]. (if it was generated using getDiff). The point is to be able to manipulate patches on their own and then re-apply when ready. Merging two patches is such an operation, and a [Diff A] -> [Diff A] -> [Diff A] would do the trick.

It looks like that is essentially what step is doing though, so I might be looking at that for a reference. Thanks for the pointer!

What do you feel about a PR possibly exporting step as a standalone function with its own name, with some descriptive documentation talking about when it is applicable?

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