Skip to content

Commit

Permalink
Merge pull request #39 from JeremiahSanders/release/1.0.0
Browse files Browse the repository at this point in the history
Release/1.0.0
  • Loading branch information
JeremiahSanders authored May 21, 2024
2 parents 59c4513 + 37b92de commit dedb0c4
Show file tree
Hide file tree
Showing 9 changed files with 293 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"cicee": {
"version": "1.5.1",
"version": "1.11.0",
"commands": [
"cicee"
]
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ using Jds.LanguageExt.Extras;
* Filters `TSuccess` results by executing `filter`. If it returns `true`, the existing value is returned. If it returns `false`, then it executes `onFalse` to create an `Exception`. Memoizes successful results.
* `TryAsync<TSuccess>.FilterAsync<TSuccess>(Func<TSuccess, Task<bool>> filter, Func<TSuccess, Exception> onFalse)`
* Filters `TSuccess` results by executing `filter`. If it returns `true`, the existing value is returned. If it returns `false`, then it executes `onFalse` to create an `Exception`. Memoizes successful results.
* `TryAsync<TSuccess>.Filter<TSuccess>(Func<TSuccess, Exception> ifCanceled, CancellationToken cancellationToken)`
* Filters based upon `cancellationToken`. If it is **not** cancelled, the existing value is returned. If it **is** cancelled, then it executes `ifCanceled` to create an `Exception`.
* `TryAsync<TSuccess>.Filter<TSuccess>(CancellationToken cancellationToken)`
* Filters based upon `cancellationToken`. If it is **not** cancelled, the existing value is returned. If it **is** cancelled, then it creates an `OperationCanceledException` with `cancellationToken`.
* `TryAsync<TSuccess>.Tap<TSuccess>(Action<TSuccess> onSuccess, Action<Exception> onFailure)`
* Executes a side effect, e.g., logging, based upon the state of the result. The current value is returned unchanged.
* `TryAsync<TSuccess>.Tap<TSuccess>(Func<TSuccess, Task> onSuccess, Func<Exception, Task> onFailure)`
Expand Down
2 changes: 1 addition & 1 deletion docs/api/Jds.LanguageExt.Extras/TryAsyncMonadExtensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class TryAsyncMonadExtensions

| name | description |
| --- | --- |
| static [Filter&lt;TSuccess&gt;](TryAsyncMonadExtensions/Filter.md)(…) | Returns a TryAsync which filters the result of *tryAsync*. When *filter* returns `false`, *onFalse* creates the failure result. (2 methods) |
| static [Filter&lt;TSuccess&gt;](TryAsyncMonadExtensions/Filter.md)(…) | Returns a TryAsync which filters the result of *tryAsync*. When *filter* returns `false`, *onFalse* creates the failure result. (4 methods) |
| static [Tap&lt;TSuccess&gt;](TryAsyncMonadExtensions/Tap.md)(…) | Execute a side effect and returns *tryAsync* result unchanged. (2 methods) |
| static [TapFailure&lt;TSuccess&gt;](TryAsyncMonadExtensions/TapFailure.md)(…) | Execute a side effect when *tryAsync* fails and returns *tryAsync* result unchanged. (2 methods) |
| static [TapSuccess&lt;TSuccess&gt;](TryAsyncMonadExtensions/TapSuccess.md)(…) | Execute a side effect when *tryAsync* succeeds and returns *tryAsync* result unchanged. (2 methods) |
Expand Down
57 changes: 55 additions & 2 deletions docs/api/Jds.LanguageExt.Extras/TryAsyncMonadExtensions/Filter.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
# TryAsyncMonadExtensions.Filter&lt;TSuccess&gt; method (1 of 2)
# TryAsyncMonadExtensions.Filter&lt;TSuccess&gt; method (1 of 4)

Returns a TryAsync which filters the result of *tryAsync* based upon whether the provided *cancellationToken* is canceled (via IsCancellationRequested).

```csharp
public static TryAsync<TSuccess> Filter<TSuccess>(this TryAsync<TSuccess> tryAsync,
CancellationToken cancellationToken)
```

| parameter | description |
| --- | --- |
| TSuccess | A success type. |
| tryAsync | A TryAsync. |
| cancellationToken | An asynchronous operation cancellation token. |

## Return Value

A TryAsync. If *cancellationToken* is not canceled: current *TSuccess* is returned. If canceled: an OperationCanceledException is returned.

## See Also

* class [TryAsyncMonadExtensions](../TryAsyncMonadExtensions.md)
* namespace [Jds.LanguageExt.Extras](../../LanguageExt.Extras.md)

---

# TryAsyncMonadExtensions.Filter&lt;TSuccess&gt; method (2 of 4)

Returns a TryAsync which filters the result of *tryAsync*. When *filter* returns `false`, *onFalse* creates the failure result.

Expand All @@ -25,7 +51,34 @@ A TryAsync. If *filter* returns true, current *TSuccess* is returned. If it retu

---

# TryAsyncMonadExtensions.Filter&lt;TSuccess&gt; method (2 of 2)
# TryAsyncMonadExtensions.Filter&lt;TSuccess&gt; method (3 of 4)

Returns a TryAsync which filters the result of *tryAsync* based upon whether the provided *cancellationToken* is canceled (via IsCancellationRequested).

```csharp
public static TryAsync<TSuccess> Filter<TSuccess>(this TryAsync<TSuccess> tryAsync,
Func<TSuccess, Exception> ifCanceled, CancellationToken cancellationToken)
```

| parameter | description |
| --- | --- |
| TSuccess | A success type. |
| tryAsync | A TryAsync. |
| ifCanceled | A function which will provide the cancellation Exception when IsCancellationRequested returns `true`. |
| cancellationToken | An asynchronous operation cancellation token. |

## Return Value

A TryAsync. If *cancellationToken* is not canceled: current *TSuccess* is returned. If canceled: the converted Exception (from *ifCanceled*) is returned.

## See Also

* class [TryAsyncMonadExtensions](../TryAsyncMonadExtensions.md)
* namespace [Jds.LanguageExt.Extras](../../LanguageExt.Extras.md)

---

# TryAsyncMonadExtensions.Filter&lt;TSuccess&gt; method (4 of 4)

Returns a TryAsync which filters the result of *tryAsync*. When *filter* returns `false`, *onFalse* creates the failure result.

Expand Down
2 changes: 1 addition & 1 deletion project-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "languageext-extras",
"description": "",
"title": "LanguageExt.Extras",
"version": "0.6.0",
"version": "1.0.0",
"ciEnvironment": {
"variables": [
{
Expand Down
2 changes: 1 addition & 1 deletion src/LanguageExt.Extras.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="LanguageExt.Core" Version="4.4.0" />
<PackageReference Include="LanguageExt.Core" Version="4.4.7" />
</ItemGroup>

</Project>
47 changes: 47 additions & 0 deletions src/TryAsyncMonadExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,53 @@ Func<TSuccess, Exception> onFalse
});
}

/// <summary>
/// Returns a <see cref="TryAsync{A}" /> which filters the result of <paramref name="tryAsync" /> based upon whether
/// the provided <paramref name="cancellationToken" /> is canceled (via
/// <see cref="System.Threading.CancellationToken.IsCancellationRequested" />).
/// </summary>
/// <param name="tryAsync">A <see cref="TryAsync{A}" />.</param>
/// <param name="ifCanceled">
/// A function which will provide the cancellation <see cref="Exception" /> when
/// <see cref="System.Threading.CancellationToken.IsCancellationRequested" /> returns <c>true</c>.
/// </param>
/// <param name="cancellationToken">An asynchronous operation cancellation token.</param>
/// <typeparam name="TSuccess">A success type.</typeparam>
/// <returns>
/// A <see cref="TryAsync{A}" />.
/// If <paramref name="cancellationToken" /> is not canceled: current <typeparamref name="TSuccess" /> is returned.
/// If canceled: the converted <see cref="Exception" /> (from <paramref name="ifCanceled" />) is returned.
/// </returns>
public static TryAsync<TSuccess> Filter<TSuccess>(
this TryAsync<TSuccess> tryAsync,
Func<TSuccess, Exception> ifCanceled,
CancellationToken cancellationToken
)
{
return tryAsync.Filter(_ => !cancellationToken.IsCancellationRequested, ifCanceled);
}

/// <summary>
/// Returns a <see cref="TryAsync{A}" /> which filters the result of <paramref name="tryAsync" /> based upon whether
/// the provided <paramref name="cancellationToken" /> is canceled (via
/// <see cref="System.Threading.CancellationToken.IsCancellationRequested" />).
/// </summary>
/// <param name="tryAsync">A <see cref="TryAsync{A}" />.</param>
/// <param name="cancellationToken">An asynchronous operation cancellation token.</param>
/// <typeparam name="TSuccess">A success type.</typeparam>
/// <returns>
/// A <see cref="TryAsync{A}" />.
/// If <paramref name="cancellationToken" /> is not canceled: current <typeparamref name="TSuccess" /> is returned.
/// If canceled: an <see cref="OperationCanceledException" /> is returned.
/// </returns>
public static TryAsync<TSuccess> Filter<TSuccess>(
this TryAsync<TSuccess> tryAsync,
CancellationToken cancellationToken
)
{
return tryAsync.Filter(_ => new OperationCanceledException(cancellationToken), cancellationToken);
}

/// <summary>
/// Execute a side effect and returns <paramref name="tryAsync" /> result unchanged.
/// </summary>
Expand Down
13 changes: 9 additions & 4 deletions tests/unit/LanguageExt.Extras.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,18 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="FluentAssertions.Analyzers" Version="0.31.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Loading

0 comments on commit dedb0c4

Please sign in to comment.