Skip to content

Commit

Permalink
Backport export of NonEmpty
Browse files Browse the repository at this point in the history
Backport of #11761

changelog_begin
changelog_end
  • Loading branch information
cocreature committed Nov 18, 2021
1 parent 327f8a9 commit 9a4c327
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 2 additions & 7 deletions compiler/damlc/daml-stdlib-src/DA/NonEmpty.daml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module DA.NonEmpty
, reverse
, find
, delete
, deleteBy
, foldl1
, foldr1
, foldr
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions compiler/damlc/tests/daml-test-files/NonEmpty.daml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (==)

0 comments on commit 9a4c327

Please sign in to comment.