intersectBy

The intersectBy function is the non-overloaded version of intersect. It is productive for infinite arguments only if the first one is a subset of the second.
The intersectBy function is the non-overloaded version of intersect.
Generic version of intersect
intersectBy is essentially a filtering operation that retains only those elements in the first stream that are present in the second stream.
>>> Stream.toList $ Stream.intersectBy (==) (Stream.fromList [1,2,2,4]) (Stream.fromList [2,1,1,3])
[1,2,2]
>>> Stream.toList $ Stream.intersectBy (==) (Stream.fromList [2,1,1,3]) (Stream.fromList [1,2,2,4])
[2,1,1]
intersectBy is similar to but not the same as joinInner:
>>> Stream.toList $ fmap fst $ Stream.joinInner (==) (Stream.fromList [1,2,2,4]) (Stream.fromList [2,1,1,3])
[1,1,2,2]
Space: O(n) where n is the number of elements in the second stream. Time: O(m x n) where m is the number of elements in the first stream and n is the number of elements in the second stream. Pre-release
Take the intersection of two tries, using a function to resolve collisions.
intersectBy returns a subsequence of the first stream which intersects with the second stream. Note that this is not a commutative operation unlike a set intersection, because of duplicate elements in the stream the order of the streams matters. This is similar to intersectBy. Note that intersectBy is a special case of innerJoin.
>>> f s1 s2 = Stream.fold Fold.toList $ Stream.intersectBy (==) (Stream.fromList s1) (Stream.fromList s2)

>>> f [1,3,4,4,5] [2,3,4,5,5]
[3,4,4,5]
First stream can be infinite, the second stream must be finite and must be capable of multiple evaluations. Space: O(n) where n is the number of elements in the second stream. Time: O(m x n) where m is the number of elements in the first stream and n is the number of elements in the second stream. Pre-release
Overloaded version of intersect.
O(n*m). Non-overloaded version of intersect.
Like intersectBy but works only on streams sorted in ascending order. Space: O(1) Time: O(m+n) Pre-release
Like intersectBy but assumes that the input streams are sorted in ascending order. To use it on streams sorted in descending order pass an inverted comparison function returning GT for less than and LT for greater than. Both streams can be infinite. Space: O(1) Time: O(m+n) Pre-release
Symbolic version of intersectBy, the result would be merged and propagate the mergeable knowledge. Can generate O(len(rhs)) cases, and O(len(lhs) * len(rhs)) constraints, assuming the predicate only generates O(1) constraints.