有时由一个遍历的输出来决定返回两个结果中的某一个,这是很有用的。optional步骤会这样:如果给定的遍历中有某个结果就返回该结果,如果没有结果就返回前一步的结果。
Sometimes it may be useful to return one of two results depending upon the outcome of an
attempted traversal. The optional step will return either the results of the provided traversal if
there is a result or the result of the prior step if there is no result.
下面的例子,在AUS和SYD之间没有直达的路线,所以optional步骤就返回了AUS顶点。
In the example below, there is no direct route between Austin (AUS) and Sydney (SYD) so the Austin
vertex is returned by the optional step.
然而在AUS和DFW之间有直达的路线,所以下面这个例子,optional步骤这次返回的就是DFW顶点了。
However, there is a route between Austin and Dallas Fort Worth (DFW) so as the example below
shows, this time the optional step returns the DFW vertex.
注意前边的查询和使用coalesce步骤查询的效果一样。如下所示,在这个场景中,如果给定的遍历没有返回结果,identity步骤将返回前一个顶点。
Note that the previous queries behave in the same way that the coalesce step would behave if used
as shown below. In this case, an identity step is used to return the prior vertex if the provided
traversal does not return a result.
浙公网安备 33010602011771号