BindAsync 函数有哪些特点?

What are the features of the BindAsync function?

BindAsync函数有什么特点?

我有一个在获取全部后使用此命令的示例方法。

public async Task<Either<Exception, List<Clients>>> BuscarClientes()
{
    return await GetAllByAsync(x => true)
                    .BindAsync(clients => 
        {
            clients = clients.Where(x => x.active == "S")
                             .OrderBy(x => x.Name)
            return clients
        }
}

此方法创建一个规则,returns 按名称排序的活动客户端列表。

它 returns 这个列表来自 GetAllByAsync 方法:

public virtual async Task<Either<Exception, IEnumerable<TEntity>>> GetAllByAsync(Expression<Func<TEntity, bool>> parameter)
{
    try
    {
        return Right<Exception, Option<TEntity>>(await DBEntity.Where(parameter).ToListAsync());
    }
    catch
    {
        return ex;
    }
}

谁能告诉我这个 BindAsync 方法是做什么用的,它是如何工作的?

我假设 BindAsync 扩展函数来自 Monacs C# 的功能扩展。

文档中描述的方法的目的是

/// <summary>
/// Transforms the <paramref name="result"/> into another <see cref="Result{T}"/> using the <paramref name="binder"/> function.
/// If the input result is Ok, returns the value of the binder call (which is <see cref="Result{T}"/> of <typeparamref name="TOut"/>).
/// Otherwise returns Error case of the Result of <typeparamref name="TOut"/>.
/// </summary>
/// <typeparam name="TIn">Type of the value in the input result.</typeparam>
/// <typeparam name="TOut">Type of the value in the returned result.</typeparam>
/// <param name="result">The result to bind with.</param>
/// <param name="binder">Function called with the input result value if it's Ok case.</param>
public static async Task<Result<TOut>> BindAsync<TIn, TOut>(this Result<TIn> result, Func<TIn, Task<Result<TOut>>> binder) =>
    result.IsOk ? await binder(result.Value) : Error<TOut>(result.Error);

意味着在应用作为 binder.

传入的函数后,它获取传入的异步操作的结果并将其包装在 Task