Created
November 13, 2024 02:03
-
-
Save mesketh/cf464e757415826131133740764df62e to your computer and use it in GitHub Desktop.
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
public record RecordA(String id) { } | |
public record RecordB(String id, String name) { } | |
@Test | |
public void testComparingTwoDifferentReactiveCollectionsOnMatchingAttribte() { | |
final Mono<List<RecordA>> recordAMonoList = Mono.just( | |
List.of(new RecordA("1"), new RecordA("2"), new RecordA("3"))); | |
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().noneMatch(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