# Why are there no curried versions of map & filter?

**URL:** <https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478>\
**Category:** New to Julia\
**Created:** [September 29, 2020, 9:44am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478 "2020-09-29T09:44:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matklad/32/17976_2.png) [@matklad](https://discourse.julialang.org/u/matklad)\
**Post date:** [September 29, 2020, 9:44am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478/1 "2020-09-29T09:44:51Z")

</div>

I’ve written the following code today:

```julia
branches = filter(strip.(readlines(`git branch --merged`))) do branch
    branch != "master" && !startswith(branch, '*')
end

```

It’s OK, but I’d love to be able to write

```julia
branches = readlines(`git branch --merged`)
    .|> strip
    |> filter(branch -> branch != "master" && !startswith(branch, '*'))
end

```

as it reads better (reading order corresponds to evaluation order and “how I think about this” order).

I think that would be possible if Base provided a single-argument version of a filter function. I know I can add this myself, but I wonder why it isn’t provided out of the box?

Are there some performance concerns with returning partially-applied functions? Or is it just not what idiomatic Julia looks like?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [September 29, 2020, 9:52am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478/2 "2020-09-29T09:52:40Z")

</div>

Maybe a macro can help

```julia
using Lazy: @>>

branches = @>> readlines(`git branch --merged`) begin
    x->strip.(x)
    filter(brach -> branch != "master" && !startswith(branch, '*'))
end

```

---

<div class="post-metadata">

**Author:** ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)\
**Post date:** [September 29, 2020, 10:13am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478/3 "2020-09-29T10:13:30Z")

</div>

```julia
julia> Base.filter(f::Function) = Base.Fix1(filter, f)
julia> Base.filter(iter) = Base.Fix2(filter, iter)
julia> [1,2,3] |> filter(isodd)
2-element Array{Int64,1}:
 1
 3
julia> isodd |> filter([1,2,3])
2-element Array{Int64,1}:
 1
 3

```

It’s certainly easy to implement. I don’t know if there’s any reason not to do it, but I think it would be a useful option to have.

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [September 29, 2020, 10:24am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478/4 "2020-09-29T10:24:24Z")

</div>

Thanks for the `Fix1` and `Fix2` !!!

---

<div class="post-metadata">

**Author:** ![simeonschaub](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/simeonschaub/32/216566_2.png) [@simeonschaub](https://discourse.julialang.org/u/simeonschaub)\
**Post date:** [September 29, 2020, 10:38am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478/5 "2020-09-29T10:38:16Z")

</div>

Also see [https://github.com/JuliaLang/julia/issues/35293](https://github.com/JuliaLang/julia/issues/35293). The problem, at least with `map`, is that `map(f)` already does something.

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [September 29, 2020, 10:47am UTC](https://discourse.julialang.org/t/why-are-there-no-curried-versions-of-map-filter/47478/6 "2020-09-29T10:47:25Z")

</div>

Since you’re not just piping but also constructing an anonymous function for filter, you may like this package:

```julia
using Underscores

branches = @_ readlines(`git branch --merged`)) .|> strip |> 
	filter(_ != "master" && !startswith(_, '*'), __)

```
