Skip to content

Commit 4b34cca

Browse files
committed
Some documentation on cursors.
1 parent dc3dea8 commit 4b34cca

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/guide/graphs.rst

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,49 @@ Or using the new syntax:
448448
graph.get_cursor(a) >> b
449449
450450
451+
Cursors
452+
:::::::
453+
454+
Cursors are simple structures that references a graph, a starting point and a finishing point. They can be used to
455+
manipulate graphs using the `>>` operator in an intuitive way.
456+
457+
To grab a cursor from a graph, you have different options:
458+
459+
.. code-block:: python
460+
461+
# the most obvious way to get a cursor, its starting point will be "BEGIN"
462+
cursor = graph.get_cursor()
463+
464+
# same thing, explicitely
465+
cursor = graph.get_cursor(BEGIN)
466+
467+
# if you try to use a graph with the `>>` operator, it will create a cursor for you, from "BEGIN"
468+
cursor = graph >> ... # same as `graph.get_cursor(BEGIN) >> ...`
469+
470+
# get a cursor pointing to nothing
471+
cursor = graph.get_cursor(None)
472+
473+
# ... or in a more readable way
474+
cursor = graph.orphan()
475+
476+
Once you get a cursor, you can use it to add nodes, concatenate it with othe cursors, etc. Everytime you call something
477+
that should result in a changed cursor, you'll get a new instance so your old cursor will still be available if you need
478+
it.
479+
480+
.. code-block:: python
481+
482+
c1 = graph.orphan()
483+
484+
# append a node, get a new cursor
485+
c2 = c1 >> node1
486+
487+
# create an orphan chain
488+
c3 = graph.orphan() >> normalize
489+
490+
# concatenate a chain to an existing cursor
491+
c4 = c2 >> c3
492+
493+
451494
Inspecting graphs
452495
:::::::::::::::::
453496

0 commit comments

Comments
 (0)