I suppose this is absent because intersecting unsorted, immutable arrays should have the worst possible runtime of Ω(n*m) without the use of extra space, and Data.Vector optimized for performance. If you want, you can write this function yourself:
import Data.Vector as V intersect :: Eq a => V.Vector a -> V.Vector a -> V.Vector a intersect x = V.filter (`V.elem` x)
Or using a temporary data structure to achieve the expected complexity of O(n + m) :
import Data.HashSet as HS intersect :: (Hashable a, Eq a) => V.Vector a -> V.Vector a -> V.Vector a intersect x = V.filter (`HS.member` set) where set = HS.fromList $ V.toList x
If you can afford to use additional memory, perhaps you can use some type of aggregate for your data, such as an array for quick random access and a hash Data.HashSet , for example Data.HashSet , for quick membership checks and always save both containers in a timely manner. This way you can reduce the asymptotic complexity for intersecting with something like O(min(n, m))
source share