GenericSteps

flatgraph.traversal.GenericSteps
final class GenericSteps[A](iterator: Iterator[A]) extends AnyVal

Attributes

Graph
Supertypes
class AnyVal
trait Matchable
class Any

Members list

Value members

Concrete methods

def and(traversals: (Iterator[A]) => Iterator[_]*): Iterator[A]

only preserves elements for which all of the given traversals have at least one result Works for arbitrary amount of 'AND' traversals.

only preserves elements for which all of the given traversals have at least one result Works for arbitrary amount of 'AND' traversals.

Attributes

Example
.and(_.label("someLabel"), _.has("someProperty"))
def cast[B]: Iterator[B]

casts all elements to given type note: this can lead to casting errors

casts all elements to given type note: this can lead to casting errors

Attributes

See also
collectAll

as a safe alternative

def choose[BranchOn >: Null, NewEnd](on: (Iterator[A]) => Iterator[BranchOn])(options: PartialFunction[BranchOn, (Iterator[A]) => Iterator[NewEnd]]): Iterator[NewEnd]

Branch step: based on the current element, match on something given a traversal, and provide resulting traversals based on the matched element. Allows to implement conditional semantics: if, if/else, if/elseif, if/elseif/else, ...

Branch step: based on the current element, match on something given a traversal, and provide resulting traversals based on the matched element. Allows to implement conditional semantics: if, if/else, if/elseif, if/elseif/else, ...

Type parameters

BranchOn

required to be >: Null because the implementation is using null as the default value. I didn't find a better way to implement all semantics with the niceties of PartialFunction, and also yolo...

NewEnd

The element type of the resulting traversal

Value parameters

on

Traversal to get to what you want to match on

options

PartialFunction from the matched element to the resulting traversal

Attributes

See also

LogicalStepsTests

Example
.choose(_.property(Name)) {
 case "L1" => _.out
 case "R1" => _.repeat(_.out)(_.maxDepth(3))
 case _ => _.in
}
def coalesce[NewEnd](options: (Iterator[A]) => Iterator[NewEnd]*): Iterator[NewEnd]
def collectAll[B](implicit ev: ClassTag[B]): Iterator[B]

collects all elements of the given class (beware of type-erasure)

collects all elements of the given class (beware of type-erasure)

Attributes

def countTrav: Iterator[Int]
def dedup: Iterator[A]

Deduplicate elements of this traversal - a.k.a. distinct, unique, ...

Deduplicate elements of this traversal - a.k.a. distinct, unique, ...

Attributes

def dedupBy(fun: A => Any): Iterator[A]

deduplicate elements of this traversal by a given function

deduplicate elements of this traversal by a given function

Attributes

def discardPathTracking: Iterator[A]
def groupBy[K](f: A => K): Map[K, List[A]]
def groupCount[B >: A]: Map[B, Int]

group elements and count how often they appear

group elements and count how often they appear

Attributes

def groupCount[B](by: A => B): Map[B, Int]

group elements by a given transformation function and count how often the results appear

group elements by a given transformation function and count how often the results appear

Attributes

def groupMap[K, B](key: A => K)(f: A => B): Map[K, List[B]]
def groupMapReduce[K, B](key: A => K)(f: A => B)(reduce: (B, B) => B): Map[K, B]
def head: A
def headOption: Option[A]
def help[B >: A](implicit elementType: ClassTag[B], searchPackages: DocSearchPackages, availableWidthProvider: AvailableWidthProvider): String

Print help/documentation based on the current elementType A. Relies on all step extensions being annotated with @Traversal / @Doc Note that this works independently of tab completion and implicit conversions in scope - it will simply list all documented steps in the classpath

Print help/documentation based on the current elementType A. Relies on all step extensions being annotated with @Traversal / @Doc Note that this works independently of tab completion and implicit conversions in scope - it will simply list all documented steps in the classpath

Attributes

def helpVerbose[B >: A](implicit elementType: ClassTag[B], searchPackages: DocSearchPackages, availableWidthProvider: AvailableWidthProvider): String
def is[B >: A](value: B): Iterator[A]

filters out everything that is not the given value

filters out everything that is not the given value

Attributes

def isPathTracking: Boolean
def iterate(): Unit

Execute the traversal without returning anything

Execute the traversal without returning anything

Attributes

def l: List[A]

Execute the traversal and convert the result to a list - shorthand for toList

Execute the traversal and convert the result to a list - shorthand for toList

Attributes

def last: A
def lastOption: Option[A]
def not(trav: (Iterator[A]) => Iterator[_]): Iterator[A]

only preserves elements if the provided traversal does not have any results - alias for whereNot

only preserves elements if the provided traversal does not have any results - alias for whereNot

Attributes

def or(traversals: (Iterator[A]) => Iterator[_]*): Iterator[A]

only preserves elements for which at least one of the given traversals has at least one result Works for arbitrary amount of 'OR' traversals.

only preserves elements for which at least one of the given traversals has at least one result Works for arbitrary amount of 'OR' traversals.

Attributes

Example
.or(_.label("someLabel"), _.has("someProperty"))
def path: Iterator[Vector[Any]]

retrieve entire path that has been traversed thus far prerequisite: enablePathTracking has been called previously

retrieve entire path that has been traversed thus far prerequisite: enablePathTracking has been called previously

Attributes

Example
myTraversal.enablePathTracking.out.out.path.toList

TODO would be nice to preserve the types of the elements, at least if they have a common supertype

def repeat[B >: A](repeatTraversal: (Iterator[A]) => Iterator[B])(implicit behaviourBuilder: (Builder[B]) => Builder[B]): Iterator[B]

Repeat the given traversal

Repeat the given traversal

By default it will continue repeating until there's no more results, not emit anything along the way, and use depth first search.

The @param behaviourBuilder allows you to configure end conditions (until|whilst|maxDepth), whether it should emit elements it passes by, and which search algorithm to use (depth-first or breadth-first).

Search algorithm: Depth First Search (DFS) vs Breadth First Search (BFS): DFS means the repeat step will go deep before wide. BFS does the opposite: wide before deep. For example, given the graph

L3 <- L2 <- L1 <- Center -> R1 -> R2 -> R3 -> R4

DFS will iterate the nodes in the order:

Center, L1, L2, L3, R1, R2, R3, R4

BFS will iterate the nodes in the order:

Center, L1, R1, R1, R2, L3, R3, R4

Attributes

See also

RepeatTraversalTests for more detail and examples for all of the above.

Note

this works for domain-specific steps as well as generic graph steps - for details please take a look at the examples in RepeatTraversalTests: both '''.followedBy''' and '''.out''' work.

Example
.repeat(_.out)                            // repeat until there's no more elements, emit nothing, use DFS
.repeat(_.out)(_.maxDepth(3))                            // perform exactly three repeat iterations
.repeat(_.out)(_.until(_.property(Name).endsWith("2")))  // repeat until the 'Name' property ends with '2'
.repeat(_.out)(_.emit)                                   // emit everything along the way
.repeat(_.out)(_.emit.breadthFirstSearch)                // emit everything, use BFS
.repeat(_.out)(_.emit(_.property(Name).startsWith("L"))) // emit if the 'Name' property starts with 'L'
def sideEffect(fun: A => ): Iterator[A]

perform side effect without changing the contents of the traversal

perform side effect without changing the contents of the traversal

Attributes

def sideEffectPF(pf: PartialFunction[A, _]): Iterator[A]

perform side effect without changing the contents of the traversal will only apply the partialFunction if it is defined for the given input - analogous to collect

perform side effect without changing the contents of the traversal will only apply the partialFunction if it is defined for the given input - analogous to collect

Attributes

def simplePath: Iterator[A]
def sortBy[B](f: A => B)(implicit ord: Ordering[B]): Seq[A]

sort elements by the value of the given transformation function

sort elements by the value of the given transformation function

Attributes

def sorted[B >: A](implicit ord: Ordering[B]): Seq[B]

sort elements by their natural order

sort elements by their natural order

Attributes

def toSetImmutable[B >: A]: Set[B]

Execute the traversal and convert the result to an immutable Set.

Execute the traversal and convert the result to an immutable Set.

Attributes

def toSetMutable[B >: A]: LinkedHashSet[B]

Execute the traversal and return a mutable.Set (better performance than immutableSet and has stable iterator order)

Execute the traversal and return a mutable.Set (better performance than immutableSet and has stable iterator order)

Attributes

def union[B](traversals: (Iterator[A]) => Iterator[B]*): Iterator[B]

union step from the current point

union step from the current point

Value parameters

traversals

to be executed from here, results are being aggregated/summed/unioned

Attributes

Example
.union(_.out, _.in)
def where(trav: (Iterator[A]) => Iterator[_]): Iterator[A]

only preserves elements if the provided traversal has at least one result

only preserves elements if the provided traversal has at least one result

Attributes

def whereNot(trav: (Iterator[A]) => Iterator[_]): Iterator[A]

only preserves elements if the provided traversal does not have any results

only preserves elements if the provided traversal does not have any results

Attributes

def within[B >: A](values: Set[B]): Iterator[A]

filters out all elements that are not in the provided set

filters out all elements that are not in the provided set

Attributes

def without[B >: A](values: Set[B]): Iterator[A]

filters out all elements that are in the provided set

filters out all elements that are in the provided set

Attributes