diff --git a/compiler/damlc/daml-stdlib-src/DA/NonEmpty.daml b/compiler/damlc/daml-stdlib-src/DA/NonEmpty.daml index 0ca74dc2ff85..f49117a4461c 100644 --- a/compiler/damlc/daml-stdlib-src/DA/NonEmpty.daml +++ b/compiler/damlc/daml-stdlib-src/DA/NonEmpty.daml @@ -22,6 +22,7 @@ module DA.NonEmpty , reverse , find , delete + , deleteBy , foldl1 , foldr1 , foldr @@ -115,13 +116,7 @@ find p (NonEmpty head tail) -- | The 'deleteBy' function behaves like 'delete', but takes a -- user-supplied equality predicate. deleteBy : (a -> a -> Bool) -> a -> NonEmpty a -> [a] -deleteBy eq a n@(NonEmpty head []) - | head `eq` a = [] - | otherwise = [head] -deleteBy eq a (NonEmpty head (t::ts)) - | head `eq` a = t::ts - | t `eq` a = head::ts - | otherwise = head :: t :: L.deleteBy eq a ts +deleteBy eq a ts = L.deleteBy eq a (toList ts) -- | Remove the first occurence of x from the non-empty list, potentially -- removing all elements. diff --git a/compiler/damlc/tests/daml-test-files/NonEmpty.daml b/compiler/damlc/tests/daml-test-files/NonEmpty.daml index 36690f5b5d70..1824c73c232f 100644 --- a/compiler/damlc/tests/daml-test-files/NonEmpty.daml +++ b/compiler/damlc/tests/daml-test-files/NonEmpty.daml @@ -46,3 +46,11 @@ testDelete = scenario do delete 1 (NonEmpty 0 [2, 1]) === [0, 2] delete 1 (NonEmpty 0 [1, 2, 1]) === [0, 2, 1] + +testDeleteBy = scenario do + deleteBy eq 1 (NonEmpty 0 []) === [0] + deleteBy eq 1 (NonEmpty 1 []) === [] + deleteBy (/=) 1 (NonEmpty 0 [1]) === [1] + where + -- Get dlint to stop complaining. + eq = (==)