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

Add valid functions #406

Open
phadej opened this issue Jan 9, 2022 · 2 comments
Open

Add valid functions #406

phadej opened this issue Jan 9, 2022 · 2 comments

Comments

@phadej
Copy link
Contributor

phadej commented Jan 9, 2022

-- check invariants
valid :: Text -> Bool

For strict text it would check that array is big enough to have offset+length, and that the slice is valid utf8.

For lazy text it would check the above, and chunk invariants.

These functions would be very useful (in writing tests) when one tinkers with internals. (Either in text itself, or other packages).

There are strictInvariant and lazyVariant for lazy text, but they error. Not entirely, but almost useless in tests.

@Bodigrim
Copy link
Contributor

Bodigrim commented Jan 9, 2022

I'd prefer isValid, but otherwise I'm in favor of this.

@phadej
Copy link
Contributor Author

phadej commented Jan 9, 2022

valid is inspired by the name in containers. Whatever works.

Also: https://hackage.haskell.org/package/perhaps-0/docs/Data-Perhaps.html is one nice way to combine error messages with Bool. (That would be great, but not worth dependency, just FYI).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants