-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Use non-null initial state for null-resilient properties in constructors #84991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f7b09e4
4c4cb30
048115d
12fdc44
adcc3fb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -296,6 +296,29 @@ public static ImmutableArray<TResult> SelectManyAsArray<TItem, TResult>(this Imm | |
| return builder.ToImmutableAndFree(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Maps and flattens an immutable array to another immutable array. | ||
| /// </summary> | ||
| /// <typeparam name="TItem">Type of the source array items</typeparam> | ||
| /// <typeparam name="TArg">Type of the argument to pass to the selector.</typeparam> | ||
| /// <typeparam name="TResult">Type of the transformed array items</typeparam> | ||
| /// <param name="array">The array to transform</param> | ||
| /// <param name="selector">A transform function to apply to each element.</param> | ||
| /// <returns>If the array's length is 0, this will return an empty immutable array.</returns> | ||
|
RikkiGibson marked this conversation as resolved.
|
||
| public static ImmutableArray<TResult> SelectManyAsArray<TItem, TArg, TResult>(this ImmutableArray<TItem> array, Func<TItem, TArg, OneOrMany<TResult>> selector, TArg arg) | ||
| { | ||
| if (array.Length == 0) | ||
| return []; | ||
|
|
||
| var builder = ArrayBuilder<TResult>.GetInstance(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting that we are not setting the capacity here like we are in the IReadOnlyCollection equivalent. But this matches the other ImmutableArray extensions around, so I guess it's fine. |
||
| foreach (var item in array) | ||
| { | ||
| selector(item, arg).AddRangeTo(builder); | ||
| } | ||
|
|
||
| return builder.ToImmutableAndFree(); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Maps and flattens a subset of immutable array to another immutable array. | ||
| /// </summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have an overload that takes ImmutableArray receiver too? Looks like this is currently being called on ImmutableArray receivers, causing boxing.