Optimize list intersection

This commit is contained in:
zuckerberg 2022-12-05 13:08:13 -07:00
parent cd80733367
commit 6b3d803456

View File

@ -20,10 +20,7 @@ let
[(take cnt l)] ++ chunksOf cnt (drop cnt l)
else [];
# same as intersectLists but takes an array of lists to intersect instead of just two
intersectManyLists = l:
if length l == 0 then []
else if length l == 1 then head l
else intersectLists (head l) (intersectManyLists (tail l));
intersectManyLists = ll: foldr intersectLists (head ll) ll;
# converts a boolean to a int (c style)
boolToInt = b: if b then 1 else 0;
# drops the last element of a list