diff --git a/Base.Tests/Structures/EnumerableExtensionTests.cs b/Base.Tests/Structures/EnumerableExtensionTests.cs index 7b8830e..8014613 100644 --- a/Base.Tests/Structures/EnumerableExtensionTests.cs +++ b/Base.Tests/Structures/EnumerableExtensionTests.cs @@ -27,7 +27,7 @@ public class EnumerableExtensionTests var baseArray = new[] { 0, 1, 2 }; var result = baseArray - .ConditionalAppend(Maybe.Just(3)) + .ConditionalAppend(Maybe.Create(3)) .ToArray(); Assert.That(result, Has.Length.EqualTo(4)); diff --git a/Base.Tests/Structures/MaybeExtensionTests.cs b/Base.Tests/Structures/MaybeExtensionTests.cs index a18f2cd..a1cdf54 100644 --- a/Base.Tests/Structures/MaybeExtensionTests.cs +++ b/Base.Tests/Structures/MaybeExtensionTests.cs @@ -12,21 +12,21 @@ public class MaybeExtensionTests public void EnumerableFirstOrEmptyTests() { Assert.AreEqual(Maybe.Empty(), Array.Empty().FirstOrEmpty()); - Assert.AreEqual(Maybe.Just("banana"), new[] { "banana" }.FirstOrEmpty()); + Assert.AreEqual(Maybe.Create("banana"), new[] { "banana" }.FirstOrEmpty()); } [Test] public void TestToMaybe() { Assert.AreEqual(Maybe.Empty(), Maybe.Empty()); - Assert.AreNotEqual(Maybe.Just(293921), Maybe.Just(2)); + Assert.AreNotEqual(Maybe.Create(293921), Maybe.Create(2)); } [Test] public void MaybeNullableTests() { Assert.IsNull(Maybe.Empty().ToNullable()); - Assert.IsNull(Maybe.Just(0, hasValue: _ => false).ToNullable()); + Assert.IsNull(Maybe.Create(0, hasValue: _ => false).ToNullable()); } [Test] diff --git a/Base.Tests/Structures/MaybeTests.cs b/Base.Tests/Structures/MaybeTests.cs index ea13305..e6ce9c2 100644 --- a/Base.Tests/Structures/MaybeTests.cs +++ b/Base.Tests/Structures/MaybeTests.cs @@ -10,7 +10,7 @@ public class MaybeTests { var emptyMaybe = Maybe.Empty(); - var result = emptyMaybe.Bind(x => Maybe.Just(x + 1)); + var result = emptyMaybe.Bind(x => Maybe.Create(x + 1)); Assert.That(result, Is.InstanceOf>()); Assert.That(result.HasValue, Is.False); @@ -19,9 +19,9 @@ public class MaybeTests [Test] public void TestBind_BindsWhenHasValue() { - var emptyMaybe = Maybe.Just(1); + var emptyMaybe = Maybe.Create(1); - var result = emptyMaybe.Bind(x => Maybe.Just(x + 1)); + var result = emptyMaybe.Bind(x => Maybe.Create(x + 1)); Assert.That(result, Is.InstanceOf>()); Assert.That(result.HasValue, Is.True); @@ -31,11 +31,11 @@ public class MaybeTests [Test] public void TestBind_BindsWhenHasValue_NewOutputType() { - var maybe = Maybe.Just(25); + var maybe = Maybe.Create(25); var result = maybe.Bind(x => x switch { - 25 => Maybe.Just("twenty-five"), + 25 => Maybe.Create("twenty-five"), _ => Maybe.Empty() }); @@ -46,9 +46,9 @@ public class MaybeTests [Test] public void EmptyBind_DoesNotBindFactory_WhenHasValue() { - var maybe = Maybe.Just(25); + var maybe = Maybe.Create(25); - var result = maybe.EmptyBind(() => Maybe.Just(30)); + var result = maybe.EmptyBind(() => Maybe.Create(30)); Assert.That(result, Is.InstanceOf>()); Assert.That(result.HasValue, Is.True); @@ -60,7 +60,7 @@ public class MaybeTests { var maybe = Maybe.Empty(); - var result = maybe.EmptyBind(() => Maybe.Just(30)); + var result = maybe.EmptyBind(() => Maybe.Create(30)); Assert.That(result, Is.InstanceOf>()); Assert.That(result.HasValue, Is.True); @@ -70,9 +70,9 @@ public class MaybeTests [Test] public void EmptyBind_DoesNotBindMaybe_WhenHasValue() { - var maybe = Maybe.Just(25); + var maybe = Maybe.Create(25); - var result = maybe.EmptyBind(Maybe.Just(30)); + var result = maybe.EmptyBind(Maybe.Create(30)); Assert.That(result, Is.InstanceOf>()); Assert.That(result.HasValue, Is.True); @@ -84,7 +84,7 @@ public class MaybeTests { var maybe = Maybe.Empty(); - var result = maybe.EmptyBind(Maybe.Just(30)); + var result = maybe.EmptyBind(Maybe.Create(30)); Assert.That(result, Is.InstanceOf>()); Assert.That(result.HasValue, Is.True); @@ -109,7 +109,7 @@ public class MaybeTests public void Cast_ToNullableReferenceType_ReturnsMaybe_WhenHasValue() { // Arrange - var maybe = Maybe.Just("banana"); + var maybe = Maybe.Create("banana"); // Act var result = maybe.Cast(); @@ -138,7 +138,7 @@ public class MaybeTests public void Cast_ToNullableValueType_ReturnsMaybe_WhenHasValue() { // Arrange - var maybe = Maybe.Just(25); + var maybe = Maybe.Create(25); // Act var result = maybe.Cast(); diff --git a/Base.Tests/Structures/NullableExtensionTests.cs b/Base.Tests/Structures/NullableExtensionTests.cs index 69aee17..c681cf1 100644 --- a/Base.Tests/Structures/NullableExtensionTests.cs +++ b/Base.Tests/Structures/NullableExtensionTests.cs @@ -12,7 +12,7 @@ public class NullableExtensionTests [Test] public void TestNullableStructOfValueToMaybe() => - Assert.AreEqual(Maybe.Just(25), ((int?)25).ToMaybe()); + Assert.AreEqual(Maybe.Create(25), ((int?)25).ToMaybe()); [Test] public void TestNullableReferenceOfNullAsMaybe() diff --git a/Base/Structures/Maybe.cs b/Base/Structures/Maybe.cs index 7fff1b0..315c553 100644 --- a/Base/Structures/Maybe.cs +++ b/Base/Structures/Maybe.cs @@ -4,8 +4,8 @@ using System; public static class Maybe { - public static Maybe Just(T value) => new(value, hasValue: true); - public static Maybe Just(T value, Func hasValue) => new(value, hasValue: hasValue(value)); + public static Maybe Create(T value) => new(value, hasValue: true); + public static Maybe Create(T value, Func hasValue) => new(value, hasValue: hasValue(value)); public static Maybe Empty() => new(val: default!, hasValue: false); } @@ -52,7 +52,7 @@ public readonly record struct Maybe HasValue ? Value : throw exFactory(); public Maybe Map(Func transformer) => - HasValue ? Maybe.Just(transformer(Value)) : Maybe.Empty(); + HasValue ? Maybe.Create(transformer(Value)) : Maybe.Empty(); public Maybe Bind(Func> binder) => HasValue ? binder(Value) : Maybe.Empty(); @@ -77,7 +77,7 @@ public readonly record struct Maybe ? default : (TOutput)Convert.ChangeType(Value, t); - return Maybe.Just(output, hasValue: _ => output != null)!; + return Maybe.Create(output, hasValue: _ => output != null)!; } catch (InvalidCastException) { @@ -85,7 +85,7 @@ public readonly record struct Maybe } } - public static implicit operator Maybe(T val) => Maybe.Just(val); + public static implicit operator Maybe(T val) => Maybe.Create(val); public static explicit operator T(Maybe val) => val.Value; diff --git a/Base/Structures/MaybeExtensions.cs b/Base/Structures/MaybeExtensions.cs index d41a3e5..a008744 100644 --- a/Base/Structures/MaybeExtensions.cs +++ b/Base/Structures/MaybeExtensions.cs @@ -23,10 +23,10 @@ public static class MaybeExtensions } public static Maybe TryGetValue(this IDictionary dict, TKey key) => - dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty(); + dict.TryGetValue(key, out var value) ? Maybe.Create(value) : Maybe.Empty(); public static Maybe TryGet(this IReadOnlyDictionary dict, TKey key) => - dict.TryGetValue(key, out var value) ? Maybe.Just(value) : Maybe.Empty(); + dict.TryGetValue(key, out var value) ? Maybe.Create(value) : Maybe.Empty(); public static T? ToNullable(this Maybe item) where T : struct => item.HasValue ? item.Value : null; diff --git a/FsBase/Extensions.fs b/FsBase/Extensions.fs index 4f7d868..6de5678 100644 --- a/FsBase/Extensions.fs +++ b/FsBase/Extensions.fs @@ -7,7 +7,7 @@ module Array = module Option = let toMaybe : 'a option -> Maybe<'a> = function - | Some x -> x |> Maybe.Just + | Some x -> x |> Maybe.Create | None -> Maybe.Empty () let fromMaybe : Maybe<'a> -> 'a option = function