From 1999323c460cdbf4c2e758caefe9172a90c3783d Mon Sep 17 00:00:00 2001 From: Wallace Kelly Date: Wed, 25 Sep 2024 10:26:43 -0400 Subject: [PATCH] Add DA.Text.isNotEmpty function --- sdk/compiler/damlc/daml-stdlib-src/DA/Text.daml | 5 +++++ sdk/compiler/damlc/tests/daml-test-files/Text.daml | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/sdk/compiler/damlc/daml-stdlib-src/DA/Text.daml b/sdk/compiler/damlc/daml-stdlib-src/DA/Text.daml index 7b8ced299d0a..e0a31a61b001 100644 --- a/sdk/compiler/damlc/daml-stdlib-src/DA/Text.daml +++ b/sdk/compiler/damlc/daml-stdlib-src/DA/Text.daml @@ -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 @@ -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 diff --git a/sdk/compiler/damlc/tests/daml-test-files/Text.daml b/sdk/compiler/damlc/tests/daml-test-files/Text.daml index 00dd3b792ce4..c547405ffeb3 100644 --- a/sdk/compiler/damlc/tests/daml-test-files/Text.daml +++ b/sdk/compiler/damlc/tests/daml-test-files/Text.daml @@ -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 " "