specter icon indicating copy to clipboard operation
specter copied to clipboard

New "find-paths" operation

Open nathanmarz opened this issue 7 years ago • 2 comments

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 https://github.com/nathanmarz/specter/issues/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 avatar Aug 28 '17 20:08 nathanmarz

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.

nathanmarz avatar Aug 29 '17 09:08 nathanmarz

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.

RokLenarcic avatar Jul 10 '18 14:07 RokLenarcic