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

New "find-paths" operation #229

Open
nathanmarz opened this issue Aug 28, 2017 · 2 comments
Open

New "find-paths" operation #229

nathanmarz opened this issue Aug 28, 2017 · 2 comments

Comments

@nathanmarz
Copy link
Collaborator

This would be a new operation like select and transform. For now this is just an idea to brainstorm and is related to the old idea #49

find-paths would find specific paths to each element matched by the path. So (find-paths [ALL :a] [{:a 1} {:a 2}]) would return something like [(path (nthpath 0) :a) (path (nthpath 1) :a)].

A use case this would help with is merging two data structures together, like two lists of lists of maps. find-paths could be used so that a transform could be done on one element while querying the other data structure for the other element. The exact semantics needed by find-paths in order to do this are so far unclear. Another issue to consider for this use case is that during the merge, each sublist should be descended into a single time, whereas iterating through individual element paths will re-traverse the same parts of the data structure repeatedly.

More use cases are needed in order to understand the precise semantics find-paths should have.

@nathanmarz
Copy link
Collaborator Author

Another possibility to consider rather than find-paths are versions of select and transform that also compute element-specific paths as they go – select-with-paths and transform-with-paths.

@RokLenarcic
Copy link

Well one use case that is very obvious, but not currently covered by Specter is merging two datastructures. For a use-case imagine you're making something like https://github.com/weavejester/meta-merge. So you're merging two nested datastructures and at each point where they differ you need to have a mechanism to inspect the difference (including inspecting metadata) to decide how to merge them. It would be also useful for ORMs style software for unrolling nested data structures into a sequence of INSERT, DELETE, UPDATE operations.

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