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

Adds push_with method #10

Merged
merged 5 commits into from
Sep 22, 2024
Merged

Conversation

chanced
Copy link
Contributor

@chanced chanced commented Sep 13, 2024

Adds push_with, allowing for T to be produced by a closure which is passed the index of the element.

Resolves #9.

@chanced chanced marked this pull request as ready for review September 13, 2024 20:31
Co-authored-by: Ibraheem Ahmed <[email protected]>
src/raw.rs Outdated
F: FnOnce(usize) -> T,
{
let index = self.next_index();
let value = f(index - 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm why the subtraction here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️

/// ```
/// let vec = boxcar::vec![0, 1];
/// vec.push_with(|index| index + 1);
/// assert_eq!(vec, [0, 1, 2]);
Copy link
Owner

@ibraheemdev ibraheemdev Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is incorrect due to above? It was inserted into index 2, so the value of the element should be 3.

Copy link
Contributor Author

@chanced chanced Sep 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh boy, i goofed that entirely.

I think I was trying to figure out what the debug output of (_, _) was, added + 1 there and then promptly forgot about it (the + 1). I later added - 1 to get the test to pass 🤦‍♂️ .

ugh, that's quiet embarrassing. Sorry about that. It should be fixed now.

@ibraheemdev
Copy link
Owner

Nice, thanks!

@ibraheemdev ibraheemdev merged commit 5ca6cfa into ibraheemdev:master Sep 22, 2024
6 checks passed
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.

Would it be possible for Vec<T> to have a push_with method?
2 participants