// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information. using System.Collections.Generic; namespace System.Linq { internal readonly struct Maybe : IEquatable> { public Maybe(T value) { HasValue = true; Value = value; } public bool HasValue { get; } public T Value { get; } public bool Equals(Maybe other) => HasValue == other.HasValue && EqualityComparer.Default.Equals(Value, other.Value); public override bool Equals(object? other) => other is Maybe m && Equals(m); public override int GetHashCode() => HasValue ? EqualityComparer.Default.GetHashCode(Value) : 0; public static bool operator ==(Maybe first, Maybe second) => first.Equals(second); public static bool operator !=(Maybe first, Maybe second) => !first.Equals(second); } }