Is there a non partial Data.Text.head function? Since Text is the default 'String' type to use with relude, it would be nice to have. Also, safe functions is one of the main reasons I chose to use relude (fantastic work on this library, by the way). Does this function already exist somewhere that I haven't seen? If not, I can have a go at writing it and making a PR if you'd like.
The text was updated successfully, but these errors were encountered:
Hi @JoshuaHall! Thanks for your kind words about Relude 😊
We reexport all Text-related functionality from the text package, and it doesn't contain the analogue of NonEmpty for lists or a safe head function. I imagine that the NonEmptyText data type will look like this:
and indeed, there are a few packages in the Haskell ecosystem that provide such type and the corresponding API:
These packages don't seem common enough, and relude goals are to be minimal in terms of dependencies and introducing custom things, so I don't think that adding one of those package to relude dependencies or reimplementing the NonEmptyText data type is an option. But you can use them in your project, should play nice together with Relude 🙂
If you want to safely extract first element of the Text, I can suggest using the uncons function from text. But uncons is a very common name, and reexporting it only for Text will cause a lot of conflicts for Relude users. I wish GHC supported qualified reexports, it would allow making Relude even more convenient and friendly!
Ideally, it would be nice if the text package provided the NonEmptyText data type, but that's a proposal for text✍️