# Why no single argument \`filter(f::function)\`?

**URL:** https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719
**Category:** Internals & Design
**Created:** [January 9, 2023, 4:01pm UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719 "2023-01-09T16:01:43Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)
#### Post date: [January 9, 2023, 4:01pm UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/1 "2023-01-09T16:01:43Z")

</div>

Is there a good reason that there is no single-argument version of `filter` that returns a filter-function? I.e. why is the following (or something similar) not in Base

```julia
filter(f::Function) = Base.Fix1(filter, f)

```

?

This would be in line with the existence of `<(x) = (y -> y < x)` or `occursin(haystack) = (needle -> (occusin(needle, haystack)))` and very useful for data processing pipelines using `|>`.

I found [this thread](https://discourse.julialang.org/t/function-chaining-with-and-filter-function/17060/4) which disusses alternatives, but gives no reason why this shouldn’t exist in Base.

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [January 9, 2023, 4:24pm UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/2 "2023-01-09T16:24:57Z")

</div>

It’s included in Julia 1.9 🙂

---

<div class="post-metadata">

### Author: ![jlbosse](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jlbosse/32/11274_2.png) [@jlbosse](https://discourse.julialang.org/u/jlbosse)
#### Post date: [January 9, 2023, 4:27pm UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/3 "2023-01-09T16:27:38Z")

</div>

Nice, looking forward to the release then!

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [January 21, 2023, 5:54am UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/4 "2023-01-21T05:54:59Z")

</div>

The next question will of course be why `map` doesn’t have such a partially-applied form 😉

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [January 21, 2023, 6:28am UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/5 "2023-01-21T06:28:59Z")

</div>

Because `map` is variadic, so it needs to work on 0 data arguments. I’m not sure this was the best option, but it’s what we have.

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [January 21, 2023, 7:30am UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/6 "2023-01-21T07:30:09Z")

</div>

Oh wow, I was expecting it to throw an error 😅

```julia
julia> f() = 5
f (generic function with 1 method)

julia> map(f)
5

```

This behavior seems to violate any meaningful notion of mapping a collection[s] to another, and it’s not in the docstring. Under what circumstance is this useful?

For comparison:

```python
>>> def f():
... return 5
...
>>> list(map(f))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: map() must have at least two arguments.

```

---

<div class="post-metadata">

### Author: ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)
#### Post date: [January 21, 2023, 8:07am UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/7 "2023-01-21T08:07:34Z")

</div>

Good point. [Change map(f) behavior · Issue #48372 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/issues/48372)

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [January 21, 2023, 8:12am UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/8 "2023-01-21T08:12:49Z")

</div>

Ah, a fun reminder of my favorite Julia code:

```julia
for zip! in zip()
    zip, zip, zip
    zip!, zip!, zip!
end

```

---

<div class="post-metadata">

### Author: ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)
#### Post date: [January 21, 2023, 8:26am UTC](https://discourse.julialang.org/t/why-no-single-argument-filter-f-function/92719/9 "2023-01-21T08:26:27Z")

</div>

It’s entertaining how [the issue](https://github.com/JuliaLang/julia/issues/35293) that it’s a duplicate of, rapidly devolves into a discussion of PR#24990 😅. Which would have it written, `map(f, _...)`.
