currently I'm resorting to ``` Functio...
# general
w
currently I'm resorting to
Copy code
FunctionApp lastApp = null!;

            foreach (var app in apps)
            {
                ComponentResourceOptions options = lastApp == null ? null! : new ComponentResourceOptions {
                    DependsOn = {
                        lastApp
                    }
                };

                var cosmosDbRoles = new CosmosDbRoles($"{StackConstants.ApplicationName.ToLower()}-{app.Key}-cosmosdbroles",
                    new CosmosDbRoleArgs()
                    {
                        ResourceGroupName = globalResourceGroup.Name,
                        FunctionIdentity = app.Value.AppIdentity,
                        CosmosDatabaseAccountName = cosmos.CosmosDatabaseAccountName,
                        CosmosDatabaseAccountId = cosmos.CosmosDatabaseAccountId
                    }, options);
                 lastApp = app.Value;
            }
s
have you tried a
reduce
(or whatever the equivalent is in .Net -
Aggregate
?)
w
the issue is passing the dependson down to the resources in order
s
actually after looking a bit more at your code i think a simple 
map
 would work (this is pseudocode since I don't know .Net languages)
Copy code
const cosmosStuff = apps.map((app, index) => {
    return {
        componentResourceOptions: index == 0 ? null! : new ComponentResourceOptions { DependsOn = { apps[index-1].Value }};
        cosmosDbRoles: new CosmosDbRoles($"{StackConstants.ApplicationName.ToLower()}-{app.Key}-cosmosdbroles",
            new CosmosDbRoleArgs() {
                ResourceGroupName = globalResourceGroup.Name,
                FunctionIdentity = app.Value.AppIdentity,
                CosmosDatabaseAccountName = cosmos.CosmosDatabaseAccountName,
                CosmosDatabaseAccountId = cosmos.CosmosDatabaseAccountId
            },
            options
        );
    }
})
w
The only difference is the index, which is admittedly marginally nicer, but still, that doesn't feel like the best option.
s
it also removes mutability and allows access to the 
new
 resources in the returned array. there might be a better way if given more specifics about the problem you're trying to solve, but without that this will be the simplest it gets
b
You could do LINQ Aggregate like @steep-toddler-94095 originally suggested. You would set the starting value to null and return the current item in the sequence each time. Then you could do it in a function without the for loop or the indexing. But I also don't know why this makes you feel dirty. It is what it is.
w
I suppose its because I want a nice factory style apply method... l have a go at a wrapper though.