Skip to content

Check for empty structures? #721

Open
@JuanGalilea

Description

@JuanGalilea

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions