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

Check for empty structures? #721

Open
JuanGalilea opened this issue Jun 8, 2022 · 1 comment
Open

Check for empty structures? #721

JuanGalilea opened this issue Jun 8, 2022 · 1 comment

Comments

@JuanGalilea
Copy link

Can't seem to find any functions that check if a structure is empty.

Though it can be implemented by composing isNothing with head but this is O(n) on any structure other than array.

While i can't figure out a O(1) version of isNothing, or head for that matter, an alternative empty checker could be implemented this other way:

// isEmpty :: (Monoid a, Setoid a) => a -> Boolean
const isEmpty = (a) => equals (a) (empty(a))

This is different from the standard implementation, as it doesn't even require it to be a foldable, but provides arguably the same functionality (at least on most structures)

Either implementation would be nice to have IMO.

@davidchambers
Copy link
Member

I agree that either of these functions would be a worthwhile addition. The monoidal function seems more natural to me.

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

No branches or pull requests

2 participants