# Cleaner API to allow \`replace\` to remove items without breaking anything

**URL:** <https://discourse.julialang.org/t/cleaner-api-to-allow-replace-to-remove-items-without-breaking-anything/8898>\
**Category:** Internals & Design\
**Created:** [February 7, 2018, 3:01pm UTC](https://discourse.julialang.org/t/cleaner-api-to-allow-replace-to-remove-items-without-breaking-anything/8898 "2018-02-07T15:01:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [February 7, 2018, 3:01pm UTC](https://discourse.julialang.org/t/cleaner-api-to-allow-replace-to-remove-items-without-breaking-anything/8898/1 "2018-02-07T15:01:00Z")

</div>

I was happy to see that the idea of using `nothing` to indicate removing an entry was removed from the PR #25697, which would have broken a lot of code (we used `nothing` to indicate JSON `null`), and I think there is a cleaner way that the functionality of being able to also remove items in a non-breaking fashion.

Now that replacements are done using `Pair`s, i.e. `key => value`, a wrapper type could be constructed to indicate that the key is to be removed instead, i.e. `Delete(key)` (`struct Delete ; val::Any ; end`), in a similar fashion that `OccursIn` and `EqualsTo` are used to wrap values for the `find*` functions now.

---

<div class="post-metadata">

**Author:** ![rfourquet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rfourquet/32/3610_2.png) [@rfourquet](https://discourse.julialang.org/u/rfourquet)\
**Post date:** [February 7, 2018, 3:13pm UTC](https://discourse.julialang.org/t/cleaner-api-to-allow-replace-to-remove-items-without-breaking-anything/8898/2 "2018-02-07T15:13:37Z")

</div>

Sounds like a good possible alternative to the other ideas (mentioned in the PR). Out of curiosity, do you have a use case for this functionality? This would help motivate updating the API. Would it be more for convenience or efficiency (one pass instead of `replace`+`filter`) ?

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [February 7, 2018, 6:19pm UTC](https://discourse.julialang.org/t/cleaner-api-to-allow-replace-to-remove-items-without-breaking-anything/8898/3 "2018-02-07T18:19:03Z")

</div>

I don’t have a use case right at the moment, it’s mainly for efficiency, and to have the same sort of functionality present with replace on a string (where you can remove a character or substring in a string using “”).  
In the past, I have needed this sort of functionality, that I had to code in C 😀.  
There’s no rush though, since with this approach, it isn’t breaking change, it could be added at any time (like for v1.1)

I just wanted to make sure that people were aware that there was a simpler alternative for the API, if this functionality was desired in `replace`.
