intersectionBy
값 동등성 대신 계산된 키로 비교하는 intersection입니다.
Iterable<A> intersectionBy<A, B>(B Function(A a) f, Iterable<A> iterable1, Iterable<A> iterable2)
FxAsyncIterable<A> intersectionByAsync<A, B>(FutureOr<B> Function(A a) f, FxAsyncIterable<A> iterable1, FxAsyncIterable<A> iterable2)
Fx<T> Fx<T>.intersectionBy<B>(B Function(T a) f, Iterable<T> other) // chain: values of the chain keyed in other
강의
differenceBy와 형태는 같고
조건만 반대입니다. intersectionBy(f, iterable1, iterable2)는
iterable2를 훑으면서
f로 만든 키가 존재하는 원소만 남깁니다. 비교
대상은 iterable1의 f-키이고, 그 키를 기준으로
중복도 제거됩니다. f는 양쪽 이터러블에 모두 적용되므로 두
이터러블은 같은 원소 타입 A를 공유해야 합니다. 비교 키 타입
B만 A와 달라도 됩니다.
식별용 필드를 공유하는 온전한 레코드 두 목록에 딱 맞는 함수입니다.
"추천" SKU 목록과 상품 카탈로그, 활성 사용자 ID 목록과 전체 사용자
객체 목록 같은 경우가 그렇습니다. intersection 자체가
intersectionBy((a) => a, iterable1, iterable2)입니다.
체인 메서드는 없습니다. data-first 함수나 그 비동기 짝을 호출하세요.
.concurrent(n)의 동시성 표시는
intersectionAsync와 똑같이
iterable2에 적용됩니다.
데모 1 · 기본
데모 2 · 비동기, 그리고 동시성
직접 해 보기
연습: intersectionBy를 'sku' 키 기준으로 써서
할인 중인 상품을 찾아보세요.
관련 항목:
intersection — 값 동등성으로 비교하는 버전 ·
differenceBy — 반대로 공통 계산 키를 가진 원소를 제외하기 ·
uniqBy — 키 기준으로 이터러블 하나에서 중복 제거 ·
compress — 나란한 불리언 마스크로 필터링