Skip to content

Commit

Permalink
feat: implement new methods in FilterService
Browse files Browse the repository at this point in the history
  • Loading branch information
elementh committed Aug 4, 2021
1 parent fcc9265 commit 79dbec8
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/Thankifi.Common.Filters/FilterService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Thankifi.Common.Filters
{
/// <inheritdoc />
public class FilterService : IFilterService
{
private readonly IEnumerable<IFilter> _filters;
Expand Down Expand Up @@ -46,5 +47,32 @@ public async Task<string> Apply(string filter, string str, CancellationToken can
return default;
}
}

/// <inheritdoc />
public async Task<string> Apply(IEnumerable<string> filters, string str, CancellationToken cancellationToken = default)
{
foreach (var filter in filters)
{
str = await Apply(filter, str, cancellationToken);
}

return str;
}

/// <inheritdoc />
public async Task<string?> ApplyOrDefault(IEnumerable<string> filters, string str, CancellationToken cancellationToken = default)
{
foreach (var filter in filters)
{
var filtered = await ApplyOrDefault(filter, str, cancellationToken);

if (filtered is not null)
{
str = filtered;
}
}

return str;
}
}
}

0 comments on commit 79dbec8

Please sign in to comment.