on master help sign in
add documentation to intersectBy and unionBY, change documentation for intersect, remove redundant patterns
6310e0eHeather
libs/base/Data/List.idr+3−4
@@ -37,15 +37,14 @@ isElem x (y :: xs) with (decEq x y)
37 mkNo f g Here = f Refl
37 mkNo f g Here = f Refl
38 mkNo f g (There x) = g x
38 mkNo f g (There x) = g x
39
39
40+||| The intersectBy function returns the intersect of two lists by user-supplied equality predicate.
40intersectBy : (a -> a -> Bool) -> List a -> List a -> List a
41intersectBy : (a -> a -> Bool) -> List a -> List a -> List a
41−intersectBy _ [] _ = []
42−intersectBy _ _ [] = []
43intersectBy eq xs ys = [x | x <- xs, any (eq x) ys]
42intersectBy eq xs ys = [x | x <- xs, any (eq x) ys]
44
43
45−||| The intersect ∩ function returns the list intersect of the two lists. For example,
44+||| Compute the intersection of two lists according to their `Eq` instance.
46|||
45|||
47||| ```idris example
46||| ```idris example
48−||| intersect [1,2,3,4] [2,4,6,8]
47+||| intersect [1, 2, 3, 4] [2, 4, 6, 8]
49||| ```
48||| ```
50|||
49|||
51intersect : (Eq a) => List a -> List a -> List a
50intersect : (Eq a) => List a -> List a -> List a
libs/prelude/Prelude/List.idr+2−3
@@ -536,12 +536,11 @@ delete = deleteBy (==)
536(\\) : (Eq a) => List a -> List a -> List a
536(\\) : (Eq a) => List a -> List a -> List a
537(\\) = foldl (flip delete)
537(\\) = foldl (flip delete)
538
538
539+||| The unionBy function returns the union of two lists by user-supplied equality predicate.
539unionBy : (a -> a -> Bool) -> List a -> List a -> List a
540unionBy : (a -> a -> Bool) -> List a -> List a -> List a
540−unionBy _ [] _ = []
541−unionBy _ _ [] = []
542unionBy eq xs ys = xs ++ foldl (flip (deleteBy eq)) (nubBy eq ys) xs
541unionBy eq xs ys = xs ++ foldl (flip (deleteBy eq)) (nubBy eq ys) xs
543
542
544−||| The union function returns the list union of the two lists. For example,
543+||| Compute the union of two lists according to their `Eq` instance.
545|||
544|||
546||| ```idris example
545||| ```idris example
547||| union ['d', 'o', 'g'] ['c', 'o', 'w']
546||| union ['d', 'o', 'g'] ['c', 'o', 'w']