Skip to content

Commit 84d1530

Browse files
authored
collectAll path tracking (#361)
* make collectAll a filter-style step for the sake of path-tracking
1 parent db89a19 commit 84d1530

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

traversal-tests/src/test/scala/overflowdb/traversal/PathTraversalTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class PathTraversalTests extends AnyWordSpec with ExampleGraphSetup {
5757
Seq(center, r1, "R1"))
5858
}
5959

60-
"collectAll: includes intermediate results (this behavior is undesired)" in {
60+
"collectAll: does not include intermediate results" in {
6161
centerTrav.enablePathTracking.collectAll[Thing].path.toList shouldBe List(
62-
Seq(center, center))
62+
Seq(center))
6363
}
6464

6565
"filter" in {

traversal/src/main/scala/overflowdb/traversal/Traversal.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ class Traversal[+A](elements: IterableOnce[A])
6161
def cast[B]: Traversal[B] =
6262
this.asInstanceOf[Traversal[B]]
6363

64-
/** collects and all elements of the given type */
65-
@Doc(info = "collects and all elements of the provided type")
66-
def collectAll[B: ClassTag]: Traversal[B] =
67-
collect { case b: B => b}
64+
/** collects all elements of the given class (beware of type-erasure) */
65+
@Doc(info = "collects all elements of the provided class (beware of type-erasure)")
66+
def collectAll[B](implicit ev: ClassTag[B]): Traversal[B] =
67+
filter(ev.runtimeClass.isInstance).asInstanceOf[Traversal[B]]
6868

6969
/** filters out everything that is _not_ the given value */
7070
@Doc(info = "filters out everything that is _not_ the given value")

0 commit comments

Comments
 (0)