Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add DA.Text.isNotEmpty function #20084

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions sdk/compiler/damlc/daml-stdlib-src/DA/Text.daml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module DA.Text
, DA.Text.explode
, DA.Text.implode
, DA.Text.isEmpty
, DA.Text.isNotEmpty
, DA.Text.length
, DA.Text.trim
, DA.Text.replace
Expand Down Expand Up @@ -70,6 +71,10 @@ implode = primitive @"BEImplodeText"
isEmpty : Text -> Bool
isEmpty = (=="")

-- | Test for non-emptiness.
isNotEmpty : Text -> Bool
isNotEmpty = (/="")

-- | Compute the number of symbols in the text.
length : Text -> Int
length = P.length . explode
Expand Down
10 changes: 10 additions & 0 deletions sdk/compiler/damlc/tests/daml-test-files/Text.daml
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,13 @@ testAsciiToUpper = script do
T.asciiToUpper "\0daml" === "\0DAML"
T.asciiToUpper "da\0⛄ml" === "DA\0⛄ML"
T.asciiToUpper "áèïõǔ" === "áèïõǔ" -- non-ASCII characters are unchanged

testIsEmpty = script do
True === T.isEmpty ""
False === T.isEmpty "hello"
False === T.isEmpty " "

testIsNotEmpty = script do
False === T.isNotEmpty ""
True === T.isNotEmpty "hello"
True === T.isNotEmpty " "
Loading