Skip to content

Conversation

@laborg
Copy link
Contributor

@laborg laborg commented Dec 21, 2024

Fix #112

Not sure if this is the fastest implementation, but now it does what I would have expected from it and is in line with the behaviour of replace/replace! on an ordinary Array

Copy link
Member

@ararslan ararslan left a comment

Choose a reason for hiding this comment

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

Implementation looks good I think, but it'd be nice to have tests for replace (currently they're only for replace!), for the error thrown when count < 0, and for the behavior when count == 0.

if R[ri] == old && reps < count
R[ri] = new
reps += 1
continue
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
continue

The continue has no effect here; there's nothing else in the loop body that appears after it so the loop will continue regardless.

if A[i] == old
A[i] = new
reps += 1
continue
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
continue

(Same comment as in the other function)

@ararslan
Copy link
Member

Is there any reason you opted not to implement replace in terms of replace!, as is done for the Base methods? It would be worth looking at the Base methods' implementations, as those account for a number of things not accounted for here at the moment, e.g. handling missing in comparisons.

@laborg
Copy link
Contributor Author

laborg commented Feb 5, 2025

Replaced by #118

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.

replace[!]() with count is broken

2 participants