-
Notifications
You must be signed in to change notification settings - Fork 440
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
feat: implement std.remove and std.removeAt #1071
Conversation
availableSince: 'upcoming', | ||
description: html.paragraphs([ | ||
||| | ||
Remove given <code>elem</code> from <code>arr</code>. |
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.
Specifically the first one found
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.
Oh it actually removes all of them! Say that then :)
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.
Actually it seems the go version only removes the 1st one and that's the semantics i'd expect from the name of the function so I guess that's what you wanted.
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.
Yes, it is for first occurrence. Made appropriate changes.
|
||
removeAt(arr, at):: [ | ||
arr[i], | ||
for i in std.range(0, std.length(arr) - 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.
Edit: Never mind, this is fine
stdlib/std.jsonnet
Outdated
@@ -1710,4 +1710,16 @@ limitations under the License. | |||
round(x):: std.floor(x + 0.5), | |||
|
|||
isEmpty(str):: std.length(str) == 0, | |||
|
|||
remove(arr, elem):: [ |
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 think you can express this as something like:
local indexes = std.find(arr, at);
if std.length(indexes) == 0 then
return arr
else
return std.removeAt(arr,indexes[0])
So it does not remove all of them
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.
Fixed
15a935f
to
74ec9b0
Compare
Implement
std.remove
andstd.removeAt
go-jsonnet PR: google/go-jsonnet#689