implement Enum Text and lowercase, uppercase conversion.
See original GitHub issueCan we add to the stdlib:
ub : Int
ub = 1114112 -- = 17 * 65,536
cplToI : [Int] -> Int
cplToI l = fst $ foldl u (0, 1) l
where u (a, p) i = (a + i * p, p * ub)
iToCplAcc : [Int] -> Int -> [Int]
iToCplAcc acc i =
let d = i / ub in
if d == 0 then
i :: acc
else
iToCplAcc (i::acc) (i - d * ub)
iToCpl : Int -> [Int]
iToCpl = iToCplAcc []
instance Enum Text where
fromEnum = cplToI . toCodePoints
toEnum = fromCodePoints . iToCpl
my goal is to also add
ia = fromEnum "a"
iz = fromEnum "z"
iA = fromEnum "A"
iZ = fromEnum "Z"
toUpperAsciiChar : Text -> Text
toUpperAsciiChar c
| ia <= ic && ic <= iz = toEnum (ic + (iA - ia))
| otherwise = c
where ic = fromEnum c
toLowerAsciiChar : Text -> Text
toLowerAsciiChar c
| iA <= ic && ic <= iZ = toEnum (ic - (iA - ia))
| otherwise = c
where ic = fromEnum c
toUpper : Text -> Text
toUpper = implode . fmap toUpperAsciiChar . explode
toLower : Text -> Text
toLower = implode . fmap toLowerAsciiChar . explode
But if there are primitives that we can leverage that accomplish toLower
and toUpper
better (ala explode), that would be great.
Issue Analytics
- State:
- Created 2 years ago
- Comments:12 (12 by maintainers)
Top Results From Across the Web
How to store enum type as lowercase string? - Stack Overflow
Your code works for me. toString and getStatus both returns lowercase strings. · @Bittenus, I try to store enum in the database as...
Read more >Converting Strings to Enums in Java | Baeldung
A quick and practical guide to converting strings to enums in Java.
Read more >Enum values are converted to uppercase #310 - GitHub
Hi, guys. I noticed that when posting variables, enums are auto-converted to uppercase. Variables = new { qr_type = qrType } public enum...
Read more >Enums | Dev Cheatsheets - Michael Currin
Use uppercase letters for your enums - they are global constants which have usable values. They are more than just types, which use...
Read more >Java - convert String to Enum object - Dirask
In java we can simply convert String to enum by using .valueOf() method on our Enum class. ... Note: We need to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@leonidr-da I have never said, there is no legitimate use cases 😉. I even supported you for adding some functions to the standard library. I am just a bit reluctant to add new LF primitives each time we find Daml too slow.
On the one hand, adding primitives does not solve the intrinsic problem of slowness, but just circumvent it in some particular use cases, while increasing maintenance cost. On the other hand, solving really Daml slowness will require rewriting the interpreter, the fewer primitives we have the easier this task will be.
Adding it to the standard library seems very reasonable to me. I agree with @remyhaemmerle-da that we should be careful wtr to primitives. I do expect that we’ll want to expand the set of Text primitives at some point but I’d rather do that in one go accompanied by design & benchmark work to only add the ones that really pay off instead of adding more and more primitives over time.