Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename HasValue to IsOk #2

Merged
merged 9 commits into from
Dec 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# Version `1.1.0-pre`

- Rewrite and update a lot of documentation.

- Rename `Result<T>.HasValue` to `IsOk`.

- Add `Result<T>.IsError`.
28 changes: 14 additions & 14 deletions src/Rascal.Tests/AsyncMappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
var r = Ok(2);
var x = await r.MapAsync(x => Task.FromResult(x.ToString()));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -18,7 +18,7 @@
var r = Err<int>("error");
var x = await r.MapAsync(x => Task.FromResult(x.ToString()));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -28,7 +28,7 @@
var r = Ok(2);
var x = await r.ThenAsync(x => Task.FromResult(Ok(x.ToString())));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -38,7 +38,7 @@
var r = Ok(2);
var x = await r.ThenAsync(_ => Task.FromResult(Err<string>("error")));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -48,7 +48,7 @@
var r = Err<int>("error");
var x = await r.ThenAsync(x => Task.FromResult(Ok(x.ToString())));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -58,17 +58,17 @@
var r = Ok(2);
var x = await r.TryMapAsync(x => Task.FromResult(x.ToString()));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

[Fact]
public async Task TryMapAsync_ReturnsErr_ForErrWithoutException()

Check warning on line 66 in src/Rascal.Tests/AsyncMappingTests.cs

View workflow job for this annotation

GitHub Actions / build-test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 66 in src/Rascal.Tests/AsyncMappingTests.cs

View workflow job for this annotation

GitHub Actions / build-test

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var r = Err<int>("error");
var x = r.TryMap(x => Task.FromResult(x.ToString()));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -78,7 +78,7 @@
var r = Ok(2);
var x = await r.TryMapAsync<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<ExceptionError>();
e.Exception.ShouldBeOfType<TestException>();
}
Expand All @@ -89,7 +89,7 @@
var r = Err<int>("error");
var x = await r.TryMapAsync<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<StringError>();
e.Message.ShouldBe("error");
}
Expand All @@ -100,7 +100,7 @@
var r = Ok(2);
var x = await r.ThenTryAsync(x => Task.FromResult(Ok(x.ToString())));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -110,7 +110,7 @@
var r = Ok(2);
var x = await r.ThenTryAsync(_ => Task.FromResult(Err<string>("error")));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -120,7 +120,7 @@
var r = Err<int>("error");
var x = await r.ThenTryAsync(x => Task.FromResult(Ok(x.ToString())));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -130,7 +130,7 @@
var r = Ok(2);
var x = await r.ThenTryAsync<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<ExceptionError>();
e.Exception.ShouldBeOfType<TestException>();
}
Expand All @@ -141,7 +141,7 @@
var r = Err<int>("error");
var x = await r.ThenTryAsync<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<StringError>();
e.Message.ShouldBe("error");
}
Expand Down
38 changes: 19 additions & 19 deletions src/Rascal.Tests/MappingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public void Map_ReturnsOk_ForOk()
var r = Ok(2);
var x = r.Map(x => x.ToString());

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -18,7 +18,7 @@ public void Map_ReturnsErr_ForErr()
var r = Err<int>("error");
var x = r.Map(x => x.ToString());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -28,7 +28,7 @@ public void Then_ReturnsOk_ForOkAndMappingReturningOk()
var r = Ok(2);
var x = r.Then(x => Ok(x.ToString()));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -38,7 +38,7 @@ public void Then_ReturnsErr_ForOkAndMappingReturningErr()
var r = Ok(2);
var x = r.Then(_ => Err<string>("error"));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -48,7 +48,7 @@ public void Then_ReturnsErr_ForErr()
var r = Err<int>("error");
var x = r.Then(x => Ok(x.ToString()));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -60,7 +60,7 @@ public void SelectMany_2_ReturnsOk_ForOkAndOtherReturningOk()
x => Ok(x.ToString()),
(x, s) => (x, s));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe((2, "2"));
}

Expand All @@ -72,7 +72,7 @@ public void SelectMany_2_ReturnsErr_ForOkAndOtherReturningErr()
x => Err<string>("error"),
(x, s) => (x, s));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -84,7 +84,7 @@ public void SelectMany_2_ReturnsErr_ForErrAndOtherReturningErr()
x => Ok(x.ToString()),
(x, s) => (x, s));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -94,7 +94,7 @@ public void TryMap_ReturnsOk_ForOkWithoutException()
var r = Ok(2);
var x = r.TryMap(x => x.ToString());

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -104,7 +104,7 @@ public void TryMap_ReturnsErr_ForErrWithoutException()
var r = Err<int>("error");
var x = r.TryMap(x => x.ToString());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -114,7 +114,7 @@ public void TryMap_ReturnsErr_ForOkWithException()
var r = Ok(2);
var x = r.TryMap<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<ExceptionError>();
e.Exception.ShouldBeOfType<TestException>();
}
Expand All @@ -125,7 +125,7 @@ public void TryMap_ReturnsErr_ForErrWithException()
var r = Err<int>("error");
var x = r.TryMap<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<StringError>();
e.Message.ShouldBe("error");
}
Expand All @@ -136,7 +136,7 @@ public void ThenTry_ReturnsOk_ForOkAndMappingReturningOk()
var r = Ok(2);
var x = r.ThenTry(x => Ok(x.ToString()));

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe("2");
}

Expand All @@ -146,7 +146,7 @@ public void ThenTry_ReturnsErr_ForOkAndMappingReturningErr()
var r = Ok(2);
var x = r.ThenTry(_ => Err<string>("error"));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -156,7 +156,7 @@ public void ThenTry_ReturnsErr_ForErrAndMappingReturningErr()
var r = Err<int>("error");
var x = r.ThenTry(x => Ok(x.ToString()));

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error?.Message.ShouldBe("error");
}

Expand All @@ -166,7 +166,7 @@ public void ThenTry_ReturnsErr_ForOkAndMappingThrowing()
var r = Ok(2);
var x = r.ThenTry<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<ExceptionError>();
e.Exception.ShouldBeOfType<TestException>();
}
Expand All @@ -177,7 +177,7 @@ public void ThenTry_ReturnsErr_ForErrAndMappingThrowing()
var r = Err<int>("error");
var x = r.ThenTry<string>(_ => throw new TestException());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
var e = x.error.ShouldBeOfType<StringError>();
e.Message.ShouldBe("error");
}
Expand All @@ -188,7 +188,7 @@ public void MapError_ReturnsOk_ForOk()
var r = Ok(2);
var x = r.MapError(_ => new TestError());

x.HasValue.ShouldBeTrue();
x.IsOk.ShouldBeTrue();
x.value.ShouldBe(2);
}

Expand All @@ -198,7 +198,7 @@ public void MapError_ReturnsErr_ForErr()
var r = Err<int>("error");
var x = r.MapError(_ => new TestError());

x.HasValue.ShouldBeFalse();
x.IsOk.ShouldBeFalse();
x.error.ShouldBeOfType<TestError>();
}
}
16 changes: 8 additions & 8 deletions src/Rascal.Tests/PreludeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void Ok_ReturnsOk()
{
var r = Ok(2);

r.HasValue.ShouldBeTrue();
r.IsOk.ShouldBeTrue();
r.value.ShouldBe(2);
}

Expand All @@ -18,7 +18,7 @@ public void Err_ReturnsErr()
{
var r = Err<int>("error");

r.HasValue.ShouldBeFalse();
r.IsOk.ShouldBeFalse();
r.error?.Message.ShouldBe("error");
}

Expand All @@ -27,7 +27,7 @@ public void ParseR_String_ReturnsOk_ForValidString()
{
var r = ParseR<int>("123", CultureInfo.InvariantCulture);

r.HasValue.ShouldBeTrue();
r.IsOk.ShouldBeTrue();
r.value.ShouldBe(123);
}

Expand All @@ -36,7 +36,7 @@ public void ParseR_String_ReturnsErr_ForInvalidString()
{
var r = ParseR<int>("24a", CultureInfo.InvariantCulture);

r.HasValue.ShouldBeFalse();
r.IsOk.ShouldBeFalse();
r.error.ShouldNotBeNull();
}

Expand All @@ -46,7 +46,7 @@ public void ParseR_Span_ReturnsOk_ForValidString()
var s = "123".AsSpan();
var r = ParseR<int>(s, CultureInfo.InvariantCulture);

r.HasValue.ShouldBeTrue();
r.IsOk.ShouldBeTrue();
r.value.ShouldBe(123);
}

Expand All @@ -56,7 +56,7 @@ public void ParseR_Span_ReturnsErr_ForInvalidString()
var s = "24a".AsSpan();
var r = ParseR<int>(s, CultureInfo.InvariantCulture);

r.HasValue.ShouldBeFalse();
r.IsOk.ShouldBeFalse();
r.error.ShouldNotBeNull();
}

Expand All @@ -65,7 +65,7 @@ public void Try_ReturnsOk_ForNoException()
{
var r = Try(() => 2);

r.HasValue.ShouldBeTrue();
r.IsOk.ShouldBeTrue();
r.value.ShouldBe(2);
}

Expand All @@ -74,7 +74,7 @@ public void Try_ReturnsErr_ForException()
{
var r = Try<int>(() => throw new TestException());

r.HasValue.ShouldBeFalse();
r.IsOk.ShouldBeFalse();
var e = r.error.ShouldBeOfType<ExceptionError>();
e.Exception.ShouldBeOfType<TestException>();
}
Expand Down
Loading