Skip to content

Could use a collect equivalent. Maybe also async.  #53

@Insomniak47

Description

@Insomniak47

Pirating from the rust stdlib it would be nice to be able to easily aggregate

List<Result<T,TErr>> 
//into
Result<List<T>, TError>;

Maybe look something like:

    public static class CollectExtensions
    {
        public static Result<IEnumerable<TValue>, TError> Collect<TValue,TError>(this IEnumerable<Result<TValue,TError>> results)
        {
            var values = new List<TValue>();
            foreach (var result in results)
            {
                if (result.IsError)
                {
                    return result.Error;
                }
                values.Add(result.Value);
            }

            return values;
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions