Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
x.RemoveAll(item => !p(item));
x.retainWhere((e) => p);
x = pack(x,.not.p())
j := 0
for i, v := range x {
if p(v) {
x[j] = x[i]
j++
}
}
for k := j; k < len(x); k++ {
x[k] = nil
}
x = x[:j]
func Filter[S ~[]T, T any](x *S, p func(T) bool) {
j := 0
for i, v := range *x {
if p(v) {
(*x)[j] = (*x)[i]
j++
}
}
var zero T
for k := j; k < len(*x); k++ {
(*x)[k] = zero
}
*x = (*x)[:j]
}
j := 0
for i, v := range x {
if p(v) {
x[j] = x[i]
j++
}
}
x = x[:j]
for (const [key, value] of x.entries()) {
if (!p(value)) x.splice(key, 1);
}
x = x.filter((e) => p(e));
x.removeIf(p.negate());
@x = grep { p($_) } @x;
del_count = 0
for i in range(len(x)):
if not p(x[i - del_count]):
del x[i - del_count]
del_count += 1
x = list(filter(p, x))
x.select!(&:p)
x.retain(p);
let mut j = 0;
for i in 0..x.len() {
if p(x[i]) {
x[j] = x[i];
j += 1;
}
}
x.truncate(j);