Created
November 12, 2024 07:21
-
-
Save mesketh/917b75360b73797d64579520f850dd7e to your computer and use it in GitHub Desktop.
comparing two different collections on common attribute reactively.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testComparingTwoDifferentReactiveCollectionsOnMatchingAttribte() { | |
final Mono<List<RecordA>> recordAMonoList = Mono.just( | |
List.of(new RecordA("1"), new RecordA("2"))); | |
final Mono<List<RecordB>> recordBMonoList = Mono.just( | |
List.of(new RecordB("1", "Record 1"), new RecordB("2", "Record 2"))); | |
recordAMonoList.zipWith(recordBMonoList).map(this::compareAndFilterLists).subscribe( | |
System.out::println, System.err::println, () -> System.out.println("Done") | |
); | |
} | |
private List<RecordA> compareAndFilterLists(Tuple2<List<RecordA>, List<RecordB>> tuple) { | |
// Comparator<IdProvider> idProviderComparator = Comparator.comparing(IdProvider::id); | |
return tuple.getT1() | |
.stream() | |
.filter(r -> tuple.getT2().stream().anyMatch(b -> b.id().equals(r.id()))) | |
.collect( | |
Collectors.toList()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment