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

Implement traversal.FocusedTransform. #130

Merged
merged 1 commit into from
Dec 31, 2020
Merged

Implement traversal.FocusedTransform. #130

merged 1 commit into from
Dec 31, 2020

Conversation

warpfork
Copy link
Collaborator

traversal.FocusedTransform is now available. It takes a starting Node, a Path, and a TransformFn (which is essentially just a function from Node to Node), and uses those instructions to build a new Node tree with the transform applied at the given path.

Like all the other traversal.* functions, it carries a traversal.Progress object around, which you can use in the TransformFn to see where you are, or to do continued traversals or transformations at deeper levels of the data while keeping a coherent track of overall position, etc.

This works even if the Path happens to cross links! If you've configured enough Loader and Storer functions in the traversal.Config, any links crossed will be automatically loaded, the transform will continue inside, and when the transform is complete, the data beyond the link will be reserialized in the same style as the original link (e.g. in the case of CIDs, that means: same multicodec will be used, same multihash will be used, etc etc), and the link will be replaced with a link to the new data, which will also have been stored.

This patch also includes a few new accessors for Path that are helpful and reasonable.

And a few new accessors for Path that are helpful and reasonable.
@warpfork
Copy link
Collaborator Author

warpfork commented Dec 27, 2020

I want to briefly confess that I also tried to work on a bigger "munge" function which would be able to do several of these focused transforms (and some kinds of bigger, non-point mutations) in aggregate. Ideally, such a function could be much more efficient than doing the same thing with a series of FocusedTransform.

That got... interesting. In order to make such a function as efficient as desired, it's necessary to reorder operations to the optimal order of application. But not all operations one can imagine wanting (such as, say, list insertions at non-end positions) are commutative. (And then, worse: in some cases, deciding whether an operation is commutative would require looking at the data, not just the target path, for example since path segments for lists vs path segments for maps are not distinguishable and ops on the latter are more commutable than ops on the former.)

Long story short, a multi-transform feature will need design work.

@warpfork warpfork merged commit e49db63 into master Dec 31, 2020
@warpfork warpfork deleted the focused-transform branch December 31, 2020 16:48
@aschmahmann aschmahmann mentioned this pull request May 14, 2021
71 tasks
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