-
Notifications
You must be signed in to change notification settings - Fork 2
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
Anvil2DExtension - Add #107
Conversation
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.
I don't know if this PR was a secret, or you just forgot to request reviews, but I found it!
/// </param> | ||
/// <typeparam name="T">The type of the array.</typeparam> | ||
/// <returns>The first index that satisfied the predicate.</returns> | ||
public static (int,int) IndexOf<T>(this T[,] array, Predicate<T> predicate) |
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.
I would suggest another name (maybe FindIndexOf<T>
?) to indicate a conditional search - IndexOf<T>
makes me think I'm just passing an element/value and asking for its index in the array.
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.
Good call. I'll follow the lead of Linq
and Array
and name the method FindIndex
/// <param name="y">The second order index</param> | ||
/// <typeparam name="T">The type of the array.</typeparam> | ||
/// <returns>The value at the specified index or default.</returns> | ||
public static T GetElementOrDefaultAt<T>(this T[,] array, int x, int y) |
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.
Would an optional explicit default value be useful? Mostly for primitives I think, so you could say array.GetElementOrDefaultAt(x, y, -1);
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.
Done. I don't think that's inline with the other *OrDefault
methods but that's fine. This could be useful in the right situation.
lol, not a secret. I think you can watch the repo if you really want notifications for every PR. This didn't touch logging so I didn't ping you! I can ping you for everything if you want! |
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.
I can think of more potentially helpful extensions, but I'm sure they'll be added as use cases come up.
Huh, I guess I was thinking of the old pr-notify group (or whatever it was called), because I normally do get emails about all new PR's, but this one slipped by. I'll check my settings, don't worry about it! |
Add a collection of extensions for working with 2 dimensional arrays.
This is a quick implementation that is being migrated from an existing project.
Follow up tasks to improve this class are: #104, #105
What is the current behaviour?
Working with 2D arrays is cumbersome.
What is the new behaviour?
Working with 2D arrays is more pleasant.
What issues does this resolve?
None
What PRs does this depend on?
Does this introduce a breaking change?