Add inner_join method to Enum

suggestion
#1

Hi everyone, this proposal is to create this method in Enum:

list1 = [1,2,3,4,5,6]
list2 = [2,3,6,2,6,8,9,0]
Enum.inner_join([list1,list2])
[2,3,4,6]
#2

MapSet.intersection/2

7 Likes
#3

In the context of Enum, ‘join’ already has a different, well-established meaning (joining elements into a string).

For what you’re after though, have a look at Flow.bounded_join/7 and Flow.window_join/8 (with :inner mode).

1 Like
#4

Another way

> list1 = [1,2,3,4,5,6]
[1, 2, 3, 4, 5, 6]
> list2 = [2,3,6,2,6,8,9,0]
[2, 3, 6, 2, 6, 8, 9, 0]
> list1 -- list1 -- list2
[2, 3, 6]
1 Like
#5

FYI:

Kernel.--/2

The complexity of a -- b is proportional to length(a) * length(b) , meaning that it will be very slow if both a and b are long lists. In such cases, consider converting each list to a MapSet and using MapSet.difference/2 .

#6

The good news is this was fixed in Erlang/OTP-22.2:

4 Likes