Repository: microsoft/onefuzz
File: src/ApiService/ApiService/onefuzzlib/orm/Orm.cs (C#)

Code before:

        public async Task<DeleteAllResult> DeleteAll(IEnumerable<(string?, string?)> keys) {
            var query = Query.Or(
                keys.Select(key =>
                    key switch {
                        (null, null) => throw new ArgumentException("partitionKey and rowKey cannot both be null"),
                        (string partitionKey, null) => Query.PartitionKey(partitionKey),
                        (null, string rowKey) => Query.RowKey(rowKey),
                        (string partitionKey, string rowKey) => Query.And(
                            Query.PartitionKey(partitionKey),
                            Query.RowKey(rowKey)
                        ),
                    }
                )
            );

            var tableClient = await GetTableClient(typeof(T).Name);
            var pages = tableClient.QueryAsync<TableEntity>(query, select: new[] { "PartitionKey, RowKey" });

            var requests = await pages
                .Chunk(MAX_TRANSACTION_SIZE)
                .Where(chunk => chunk.Count > 0)
                .Select(chunk =>
                    chunk.Select(e => new TableTransactionAction(TableTransactionActionType.Delete, e))
                )
                .Select(t => tableClient.SubmitTransactionAsync(t))
                .ToArrayAsync();

            var responses = await System.Threading.Tasks.Task.WhenAll(requests);
            var (successes, failures) = responses
                .SelectMany(x => x.Value)
                .Aggregate(
                    (0, 0),
                    ((int Successes, int Failures) acc, Response current) =>
                        current.IsError
                        ? (acc.Successes, acc.Failures + 1)
                        : (acc.Successes + 1, acc.Failures)
            );

            return new DeleteAllResult(successes, failures);
        }
    }


    public interface IStatefulOrm<T, TState> : IOrm<T> where T : StatefulEntityBase<TState> where TState : Enum {
        Async.Task<T> ProcessStateUpdate(T entity);

        Async.Task<T?> ProcessStateUpdates(T entity, int MaxUpdates = 5);
    }



Review comment (suggestion):
I would merge these two `Select`s:

```suggestion
                .Select(chunk => {
                    var t = chunk.Select(e => new TableTransactionAction(TableTransactionActionType.Delete, e));
                    return tableClient.SubmitTransactionAsync(t));
                });
```

Code after:

        public async Task<DeleteAllResult> DeleteAll(IEnumerable<(string?, string?)> keys) {
            var query = Query.Or(
                keys.Select(key =>
                    key switch {
                        (null, null) => throw new ArgumentException("partitionKey and rowKey cannot both be null"),
                        (string partitionKey, null) => Query.PartitionKey(partitionKey),
                        (null, string rowKey) => Query.RowKey(rowKey),
                        (string partitionKey, string rowKey) => Query.And(
                            Query.PartitionKey(partitionKey),
                            Query.RowKey(rowKey)
                        ),
                    }
                )
            );

            var tableClient = await GetTableClient(typeof(T).Name);
            var pages = tableClient.QueryAsync<TableEntity>(query, select: new[] { "PartitionKey, RowKey" });

            var requests = await pages
                .Chunk(MAX_TRANSACTION_SIZE)
                .Select(chunk => {
                    var transactions = chunk.Select(e => new TableTransactionAction(TableTransactionActionType.Delete, e));
                    return tableClient.SubmitTransactionAsync(transactions);
                })
                .ToListAsync();

            var responses = await System.Threading.Tasks.Task.WhenAll(requests);
            var (successes, failures) = responses
                .SelectMany(x => x.Value)
                .Aggregate(
                    (0, 0),
                    ((int Successes, int Failures) acc, Response current) =>
                        current.IsError
                        ? (acc.Successes, acc.Failures + 1)
                        : (acc.Successes + 1, acc.Failures)
            );

            return new DeleteAllResult(successes, failures);
        }
    }


    public interface IStatefulOrm<T, TState> : IOrm<T> where T : StatefulEntityBase<TState> where TState : Enum {
        Async.Task<T> ProcessStateUpdate(T entity);

        Async.Task<T?> ProcessStateUpdates(T entity, int MaxUpdates = 5);
    }


    public abstract class StatefulOrm<T, TState, TSelf> : Orm<T>, IStatefulOrm<T, TState> where T : StatefulEntityBase<TState> where TState : Enum {