>>> [1,2,3,4] `intersect` [2,4,6,8] [2,4]If equal elements are present in both lists, an element from the first list will be used, and all duplicates from the second list quashed:
>>> import Data.Semigroup >>> intersect [Arg () "dog"] [Arg () "cow", Arg () "cat"] [Arg () "dog"]However if the first list contains duplicates, so will the result.
>>> "coot" `intersect` "heron" "oo" >>> "heron" `intersect` "coot" "o"If the second list is infinite, intersect either hangs or returns its first argument in full. Otherwise if the first list is infinite, intersect might be productive:
>>> intersect [100..] [0..] [100,101,102,103... >>> intersect [0] [1..] * Hangs forever * >>> intersect [1..] [0] * Hangs forever * >>> intersect (cycle [1..3]) [2] [2,2,2,2...
>>> [1,2,3,4] `intersect` [2,4,6,8] [2,4]If the first list contains duplicates, so will the result.
>>> [1,2,2,3,4] `intersect` [6,4,4,2] [2,2,4]It is a special case of intersectBy, which allows the programmer to supply their own equality test. If the element is found in both the first and the second list, the element from the first list will be used.
>>> [1,2,3,4] `intersect` [2,4,6,8] [2,4]If equal elements are present in both lists, an element from the first list will be used, and all duplicates from the second list quashed:
>>> import Data.Semigroup >>> intersect [Arg () "dog"] [Arg () "cow", Arg () "cat"] [Arg () "dog"]However if the first list contains duplicates, so will the result.
>>> "coot" `intersect` "heron" "oo" >>> "heron" `intersect` "coot" "o"If the second list is infinite, intersect either hangs or returns its first argument in full. Otherwise if the first list is infinite, intersect might be productive:
>>> intersect [100..] [0..] [100,101,102,103... >>> intersect [0] [1..] * Hangs forever * >>> intersect [1..] [0] * Hangs forever * >>> intersect (cycle [1..3]) [2] [2,2,2,2...
>>> intersect (slist [1,2,3,4]) (slist [2,4,6,8]) Slist {sList = [2,4], sSize = Size 2}If the first list contains duplicates, so will the result.
>>> intersect (slist [1,2,2,3,4]) (slist [6,4,4,2]) Slist {sList = [2,2,4], sSize = Size 3}If the first slist is infinite, so will be the result. If the element is found in both the first and the second slist, the element from the first slist will be used. It is a special case of intersectBy.