Skip to content

Commit

Permalink
Implement 'Contains' Equality
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Jan 12, 2025
1 parent 4f1153e commit 7566a1a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 16 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections.Generic;

namespace System;

partial struct Optional<T>
{
// TODO: Add the tests and open the methods/operators

internal bool Contains(T value, IEqualityComparer<T>? comparer)
=>
InnerContains(value, comparer ?? EqualityComparer<T>.Default);

internal bool Contains(T value)
=>
InnerContains(value, EqualityComparer<T>.Default);

internal static bool Equals(Optional<T> left, T right, IEqualityComparer<T>? comparer)
=>
left.Contains(right, comparer);

internal static bool Equals(Optional<T> left, T right)
=>
left.Contains(right);

//public static bool operator ==(Optional<T> left, T right)
// =>
// left.Contains(right);

//public static bool operator !=(Optional<T> left, T right)
// =>
// left.Contains(right) is not true;

internal static bool Equals(T left, Optional<T> right, IEqualityComparer<T>? comparer)
=>
right.Contains(left, comparer);

internal static bool Equals(T left, Optional<T> right)
=>
right.Contains(left);

//public static bool operator ==(T left, Optional<T> right)
// =>
// right.Contains(left);

//public static bool operator !=(T left, Optional<T> right)
// =>
// right.Contains(left) is not true;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Collections.Generic;

namespace System;

partial class Optional
{
// TODO: Add the tests and open the methods

internal static bool Equals<T>(Optional<T> left, T right, IEqualityComparer<T>? comparer)
=>
left.Contains(right, comparer);

internal static bool Equals<T>(Optional<T> left, T right)
=>
left.Contains(right);

internal static bool Equals<T>(T left, Optional<T> right, IEqualityComparer<T>? comparer)
=>
right.Contains(left, comparer);

internal static bool Equals<T>(T left, Optional<T> right)
=>
right.Contains(left);
}

0 comments on commit 7566a1a

Please sign in to comment.