| //// |
| Licensed to the Apache Software Foundation (ASF) under one |
| or more contributor license agreements. See the NOTICE file |
| distributed with this work for additional information |
| regarding copyright ownership. The ASF licenses this file |
| to you under the Apache License, Version 2.0 (the |
| "License"); you may not use this file except in compliance |
| with the License. You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, |
| software distributed under the License is distributed on an |
| "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| KIND, either express or implied. See the License for the |
| specific language governing permissions and limitations |
| under the License. |
| //// |
| [[operating-on-dropped-elements]] |
| == Operating on Dropped Elements |
| |
| One common scenario that happens when dropping elements using a traversal is the desire to perform |
| some sort of operation on the elements being removed. This simplest is returning |
| the number of elements being dropped from the traversal, which is shown in the example below from the |
| "modern" graph. |
| |
| [gremlin-groovy,modern] |
| ---- |
| g.V().has('lang', 'java').sideEffect(drop()).count() |
| ---- |
| |
| While this may seem a bit counterintuitive, what is occurring in this recipe is that the `sideEffect()` |
| step is performing the `drop()` while each of the input traverser is still passed along to the remainder |
| of the traversal, which in this case is a `count()` operation. This pattern can be extended beyond a |
| simple count to perform a variety of more complex traversals based on the dropped traversal such as |
| removing child nodes in the case of a tree or setting properties on adjacent vertices. |
| |
| WARNING: Some graph implementations may not behave in the same manner as TinkerGraph when using |
| side effects, such as the `sideEffect(drop())`. While the specified pattern works for TinkerGraph, we |
| recommend that this pattern be tested on your chosen implementation to ensure that it functions in the |
| same manner. |