Back to Lo

It Intersectby

docs/data/it-intersectby.md

1.53.0661 B
Original Source

Returns the intersection between given collections using a custom key selector function.

Examples:

go
seq1 := func(yield func(int) bool) {
    _ = yield(1)
    _ = yield(2)
    _ = yield(3)
    _ = yield(4)
}
seq2 := func(yield func(int) bool) {
    _ = yield(2)
    _ = yield(3)
    _ = yield(5)
}
seq3 := func(yield func(int) bool) {
    _ = yield(3)
    _ = yield(2)
    _ = yield(6)
}

transform := func(v int) string {
  return strconv.Itoa(v)
}

intersection := it.IntersectBy(transform, seq1, seq2, seq3)

var result []int
for v := range intersection {
    result = append(result, v)
}
// result contains 2, 3 (elements present in all sequences)