# Is there a direct Julia equivalent of Rust's \`retain()\` method?

**URL:** https://discourse.julialang.org/t/is-there-a-direct-julia-equivalent-of-rusts-retain-method/57391
**Category:** General Usage
**Created:** [March 17, 2021, 3:00pm UTC](https://discourse.julialang.org/t/is-there-a-direct-julia-equivalent-of-rusts-retain-method/57391 "2021-03-17T15:00:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)
#### Post date: [March 17, 2021, 3:00pm UTC](https://discourse.julialang.org/t/is-there-a-direct-julia-equivalent-of-rusts-retain-method/57391/1 "2021-03-17T15:00:57Z")

</div>

Is there a direct Julia equivalent of Rust’s `retain()` method?

Note that the original poster on Slack cannot see your response here on Discourse. Consider _transcribing the appropriate answer back to Slack_, or pinging the poster here on Discourse so they can _follow this thread_.  
[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1615993229019500?thread_ts=1615993229.019500&cid=C6A044SQH) [(More Info)](https://github.com/JuliaCommunity/SlackBridge)

---

<div class="post-metadata">

### Author: ![jakobnissen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jakobnissen/32/13477_2.png) [@jakobnissen](https://discourse.julialang.org/u/jakobnissen)
#### Post date: [March 17, 2021, 3:25pm UTC](https://discourse.julialang.org/t/is-there-a-direct-julia-equivalent-of-rusts-retain-method/57391/2 "2021-03-17T15:25:48Z")

</div>

Yes. `Iterators.filter` (as already answered on Slack)

---

<div class="post-metadata">

### Author: ![arsh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/arsh/32/9073_2.png) [@arsh](https://discourse.julialang.org/u/arsh)
#### Post date: [March 17, 2021, 3:43pm UTC](https://discourse.julialang.org/t/is-there-a-direct-julia-equivalent-of-rusts-retain-method/57391/3 "2021-03-17T15:43:33Z")

</div>

Other similar options as suggested by Jerry Ling and Karl Dyrhage:  
`filter!(x -> foo(x, a, b), [...])` incase `foo` takes more than one arguments.

or

```julia
filter!([...]) do element
    foo(element, a, b)
end

```
