Created
November 13, 2024 02:08
-
-
Save mesketh/248e7795ed0c1096c666fc960bc19b70 to your computer and use it in GitHub Desktop.
This file contains 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 testFilteringRecordAListWithIdsNotFoundOnRecordBList() { | |
final Mono<List<RecordA>> recordAMonoList = Mono.just( | |
List.of(new RecordA("1"), new RecordA("2"), new RecordA("3"), new RecordA("4"))); | |
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("Finished filtering RecordA list") | |
); | |
} | |
private List<RecordA> compareAndFilterLists(Tuple2<List<RecordA>, List<RecordB>> tuple) { | |
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