Skip to content

IsHomogeneous: test all elements of a sequence for equality #698

Open
@Orace

Description

@Orace

I propose for:

(bool? isHomogeneous, T value) IsHomogeneous<T>(this IEnumerable<T> source, IEqualitityComparer<T> comparer = null);

DefaultEqualitityComparer<T> is used if comparer is null.
The return tuple contains:

  • isHomogeneous:
    • null if the source is empty
    • true if the source has one element or if all the elements in the source are equals to the first element relatively to comparer
    • false otherwise.
  • value: the first value of the source if isHomogeneous is true, default(T) otherwise.

I'm open to give this method any other relevant name.

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