Skip to content

Commit

Permalink
Improve Optional Comparison model
Browse files Browse the repository at this point in the history
  • Loading branch information
andreise committed Jan 5, 2025
1 parent f8a2e7b commit 8e297dc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.

This file was deleted.

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

namespace System;

partial struct Optional<T>
{
internal sealed class InternalComparer(IComparer<T> comparer) : IComparer<Optional<T>>
{
public int Compare(Optional<T> x, Optional<T> y)
=>
x.InternalCompareTo(y, comparer);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace System;

partial struct Optional<T>
{
// TODO: Add the tests and open the method
internal static IComparer<Optional<T>> CreateComparer(IComparer<T> comparer)
=>
new InternalComparer(comparer ?? throw new ArgumentNullException(nameof(comparer)));
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace System;
using System.Collections.Generic;

namespace System;

partial class Optional
{
Expand All @@ -7,4 +9,9 @@ internal static int Compare<T>(Optional<T> left, Optional<T> right)
where T : IComparable<T>
=>
left.CompareTo(right);

// TODO: Add the tests and open the method
internal static IComparer<Optional<T>> CreateComparer<T>(IComparer<T> comparer)
=>
new Optional<T>.InternalComparer(comparer ?? throw new ArgumentNullException(nameof(comparer)));
}

0 comments on commit 8e297dc

Please sign in to comment.