https://pulumi.com logo
Title
b

boundless-monkey-2042

06/02/2021, 8:20 PM
Is it possible to cast the result of a LINQ Enumerable.Select 'System.Collections.Generic.IEnumerable<System.Collections.Generic.IEnumerable<Pulumi.AzureNative.Network.Inputs.SecurityRuleArgs>>' to 'Pulumi.InputList<Pulumi.AzureNative.Network.Inputs.SecurityRuleArgs>' ? All the values come from directly from a Pulumi.dev.yaml none are Outputs
t

tall-librarian-49374

06/02/2021, 8:31 PM
Yes, you’d need to flatten the collection, e.g. with
SelectMany
, I think.
b

boundless-monkey-2042

06/02/2021, 8:34 PM
Thank you, I'll try that. Is there a docs you're aware of that covers this?
t

tall-librarian-49374

06/02/2021, 8:40 PM
Not sure… if you have a repro snippet, I can take a look.
b

boundless-monkey-2042

06/02/2021, 8:40 PM
from the docs --> Implicit(T[] to InputList<T>) so applying a .ToArray() to the result SecurityRules = (_rules.Select(r => MapSecurityRules (r))).ToArray(), worked‼️
t

tall-librarian-49374

06/02/2021, 8:53 PM
Yes, you can assign a collection to InputList
w

worried-city-86458

06/02/2021, 11:20 PM
You'll still want to flatten first with
SelectMany
?
b

boundless-monkey-2042

06/03/2021, 6:54 PM
Sean, do you have an example? Why would I "flatten" my yaml?
w

worried-city-86458

06/03/2021, 7:03 PM
You have
IEnumerable<IEnumerable<SecurityRuleArgs>>
presumably from inner
MapSecurityRules
, so to flatten use:
SecurityRules = _rules.SelectMany(rule => MapSecurityRules(rule)).ToArray() // or ToImmutableArray()
then if I read that correctly you should be able to use method group syntax:
SecurityRules = _rules.SelectMany(MapSecurityRules).ToArray() // or ToImmutableArray()
You flatten it to unroll the inner enumerable into the outer enumerable, if that makes sense. i.e. effectively this converts
IEnumerable<IEnumerable<SecurityRuleArgs>>
to
IEnumerable<SecurityRuleArgs>
b

boundless-monkey-2042

06/10/2021, 4:48 AM
Excellent! thank you Sean