#String utils like `is_digit`, `is_ascii`, etc.

1 messages · Page 1 of 1 (latest)

wind flint
#

When practicing a bit of AoC in Gleam, I ended up doing this function:

fn is_digit(input: String) {
  list.range(0, 9) |> list.map(int.to_string) |> list.contains(any: input)
}

So I wanted to ask if there is some library that provides some string utils like these? Or if are there some plans to add these things to Gleam stdlib in the future?

Thanks lucyhappy

narrow harness
#

Unlikely these will be added to the stdlib

rose thicket
wind flint
#

Hmm, would it make sense then to make a utils library for these (and more) specific string use cases? If it doesn't exist one yet

rose thicket
#

not really

#

gleam strings are utf8

#

we dont have packages that explicitly encourage bad code, almost every time a developer assumes they can work with ascii they are wrong 😅

#

AoC is an obvious exception, but advent_of_code_helpers as a package name would be much much better than string_utils

wind flint
wind flint
#

If I'm not wrong, ASCII strings (not extended ASCII) are represented in bytes equally as in UTF-8

severe citrus
#

You are not wrong there. Of course you're assuming that the input contains arabic (ASCII) numerals instead of some other numerals, but that's a more reasonable assumption in most cases.