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

Non partial Data.Text.head #330

Closed
JoshuaHall opened this issue Sep 2, 2020 · 2 comments
Closed

Non partial Data.Text.head #330

JoshuaHall opened this issue Sep 2, 2020 · 2 comments
Labels
question Further information is requested

Comments

@JoshuaHall
Copy link

JoshuaHall commented Sep 2, 2020

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.

@chshersh chshersh added the question Further information is requested label Sep 3, 2020
@chshersh
Copy link
Contributor

chshersh commented Sep 3, 2020

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:

data NonEmptyText = NonEmptyText Char Text

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 ✍️

@JoshuaHall
Copy link
Author

JoshuaHall commented Sep 3, 2020

That makes sense, I'll use another package. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants