Path: redb-route/redb.Route/Predicates/LambdaPredicate.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route/Predicates/LambdaPredicate.cs
----
using redb.Route.Abstractions;
namespace redb.Route.Predicates;
///
/// Predicate that wraps a delegate for inline predicate logic.
///
public class LambdaPredicate : IPredicate
{
private readonly Func _predicate;
///
/// Initializes a new instance with the specified delegate.
///
/// The delegate that evaluates the predicate condition.
public LambdaPredicate(Func predicate)
{
_predicate = predicate ?? throw new ArgumentNullException(nameof(predicate));
}
///
public bool Matches(IExchange exchange)
{
return _predicate(exchange);
}
///
public Task MatchesAsync(IExchange exchange)
=> Task.FromResult(Matches(exchange));
}