Skip to content

Commit

Permalink
v0.11.0 (#86)
Browse files Browse the repository at this point in the history
* `Chainable#crossSelf()`
  • Loading branch information
chainables authored May 12, 2021
1 parent 55ce227 commit 017ebd9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.github.chainables</groupId>
<artifactId>chainable</artifactId>
<version>0.10.1</version>
<version>0.11.0</version>
<packaging>jar</packaging>

<name>${project.groupId}:${project.artifactId}</name>
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/github/chainables/chainable/Chainable.java
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,14 @@ default <V> Chainable<Pair<T, V>> cross(Iterable<? extends V> items) {
return Chainables.cross(this, items);
}

/**
* Produces all the pairwise combinations of this chain with itself.
* @return a chain of pairs of all the combinations of items from this chain
*/
default <V> Chainable<Pair<T, T>> crossSelf() {
return Chainables.cross(this, this);
}

/**
* Traverses the items in a depth-first (pre-order) manner, by visiting the children of each item in the chain, as returned by the
* specified {@code childExtractor} before visting its siblings, in a de-facto recursive manner.
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/github/chainables/chainable/ChainableTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,30 @@ public void testCross() {
assertTrue(crossChainEmpty.isEmpty());
}

@Test
public void testCrossSelft() {
// Given
String[] items = { "a", "b", "c", "d" };
long expectedLength = items.length * items.length;
Chainable<String> chain = chain(items);
List<Pair<String, String>> expected = new ArrayList<>();

for (int i = 0; i < items.length; i++) {
for (int j = 0; j < items.length; j++) {
Pair<String, String> pair = Pair.from(items[i], items[j]);
expected.add(pair);
}
}

// When
Chainable<Pair<String, String>> crossChain = chain.crossSelf();
ChainableList<Pair<String, String>> actual = crossChain.toList();

// Then
assertEquals(expectedLength, actual.size());
assertTrue(actual.containsAll(expected));
}

@Test
public void testDepthFirst() {
// Given
Expand Down

0 comments on commit 017ebd9

Please sign in to comment.