doc.go 2.97 KB
Newer Older
1
// This package provides functional utilities for traversing and transforming
tavit ohanian's avatar
tavit ohanian committed
2
// LD nodes.
3 4 5 6 7 8
//
// The traversal.Path type provides a description of how to perform
// several steps across a Node tree.  These are dual purpose:
// Paths can be used as instructions to do some traversal, and
// Paths are accumulated during traversals as a log of progress.
//
tavit ohanian's avatar
tavit ohanian committed
9
// "Focus" functions provide syntactic sugar for using ld.Path to jump
10 11
// to a Node deep in a tree of other Nodes.
//
12
// "FocusedTransform" functions can do the same such deep jumps, and support
13
// mutation as well!
tavit ohanian's avatar
tavit ohanian committed
14
// (Of course, since ld.Node is an immutable interface, more precisely
15 16 17
// speaking, "transformations" are implemented rebuilding trees of nodes to
// emulate mutation in a copy-on-write way.)
//
18 19 20 21
// "Walk" functions perform a walk of a Node graph, and apply visitor
// functions multiple Nodes.  The more advanced Walk functions can be guided
// by Selectors, which provide a declarative mechanism for guiding the
// traversal and filtering which Nodes are of interest.
22 23
// (See the selector sub-package for more detail.)
//
24 25
// "WalkTransforming" is similar to Traverse, but with support for mutations.
// Like "FocusTransform", "WalkTransforming" operates in a copy-on-write way.
26
//
27
// All of these functions -- the "Focus*" and "Walk*" family alike --
28
// work via callbacks: they do the traversal, and call a user-provided function
29
// with a handle to the reached Node.  Further "Focus" and "Walk" can be used
30 31
// recursively within this callback.
//
32
// All of these functions -- the "Focus*" and "Walk*" family alike --
33
// include support for automatic resolution and loading of new Node trees
tavit ohanian's avatar
tavit ohanian committed
34
// whenever LD Links are encountered.  This can be configured freely
35
// by providing LinkLoader interfaces to the traversal.Config.
36 37 38
//
// Some notes on the limits of usage:
//
39
// The "*Transform" family of methods is most appropriate for patterns of usage
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
// which resemble point mutations.
// More general transformations -- zygohylohistomorphisms, etc -- will be best
// implemented by composing the read-only systems (e.g. Focus, Traverse) and
// handling the accumulation in the visitor functions.
//
// (Why?  The "point mutation" use-case gets core library support because
// it's both high utility and highly clear how to implement it.
// More advanced transformations are nontrivial to provide generalized support
// for, for three reasons: efficiency is hard; not all existing research into
// categorical recursion schemes is necessarily applicable without modification
// (efficient behavior in a merkle-tree context is not the same as efficient
// behavior on uniform memory!); and we have the further compounding complexity
// of the range of choices available for underlying Node implementation.
// Therefore, attempts at generalization are not included here; handling these
// issues in concrete cases is easy, so we call it an application logic concern.
// However, exploring categorical recursion schemes as a library is encouraged!)
//
package traversal