Skip to content
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

Merged
merged 3 commits into from
Aug 24, 2022
Merged

Anvil2DExtension - Add #107

merged 3 commits into from
Aug 24, 2022

Conversation

mbaker3
Copy link
Member

@mbaker3 mbaker3 commented Aug 17, 2022

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?

  • None (Except the PR in the project this was pulled from)

Does this introduce a breaking change?

  • Yes
  • No

Copy link
Contributor

@tjvezina tjvezina left a 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)
Copy link
Contributor

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.

Copy link
Member Author

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)
Copy link
Contributor

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);

Copy link
Member Author

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.

@mbaker3
Copy link
Member Author

mbaker3 commented Aug 24, 2022

I don't know if this PR was a secret, or you just forgot to request reviews, but I found it!

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!

Copy link
Contributor

@tjvezina tjvezina left a 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.

@mbaker3 mbaker3 merged commit ffadb19 into main Aug 24, 2022
@mbaker3 mbaker3 deleted the feature-Array2DExtension branch August 24, 2022 01:14
@tjvezina
Copy link
Contributor

I can ping you for everything if you want!

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants