# Predicate function for indexing at a particular place?

**URL:** <https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531>\
**Category:** General Usage\
**Created:** [July 29, 2026, 11:06pm UTC](https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531 "2026-07-29T23:06:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brainandforce](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brainandforce/32/211054_2.png) [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Post date:** [July 29, 2026, 11:06pm UTC](https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531/1 "2026-07-29T23:06:50Z")

</div>

Is there a predicate function for indexing a collection at a particular place? Obviously we can get the first index with `first` and last index with `last`, but if we want to `map` over a bunch of collections at the same time at an arbitrary index, it seems like the best solution is to use an anonymous function:

```julia-repl
julia> dicts = [Dict(:a => rand(), :b => rand(), :c => rand()) for _ in 1:10]
10-element Vector{Dict{Symbol, Float64}}:
 Dict(:a => 0.11276876680317638, :b => 0.5804642747922222, :c => 0.297099967718748)
 Dict(:a => 0.7568185643585452, :b => 0.18558105407404357, :c => 0.49042900522403876)
 Dict(:a => 0.22835661901657534, :b => 0.6878438917607254, :c => 0.5632635427646513)
 Dict(:a => 0.04977469205425644, :b => 0.6238572606181523, :c => 0.786197053098311)
 Dict(:a => 0.24199448074683105, :b => 0.866325424971575, :c => 0.07220151576792944)
 Dict(:a => 0.8800524440688102, :b => 0.6974405419646451, :c => 0.8877058911766074)
 Dict(:a => 0.7387397201653839, :b => 0.138364937111067, :c => 0.2863876875531587)
 Dict(:a => 0.06326531923807488, :b => 0.044989524502915934, :c => 0.04682015970973652)
 Dict(:a => 0.9142312773398198, :b => 0.5299189376907916, :c => 0.30385896402788926)
 Dict(:a => 0.0345049851722935, :b => 0.3487002109632641, :c => 0.8352369435137795)

julia> map(d -> d[:a], dicts)
10-element Vector{Float64}:
 0.11276876680317638
 0.7568185643585452
 0.22835661901657534
 0.04977469205425644
 0.24199448074683105
 0.8800524440688102
 0.7387397201653839
 0.06326531923807488
 0.9142312773398198
 0.0345049851722935

```

We have `Returns(x)` as a shorthand for `_ -> x`, which can be useful if we need to create an `NTuple` with default values, for example:

```julia-repl
julia> ntuple(Returns(0), Val(4))
(0, 0, 0, 0)

```

Does a similar shorthand exist for indexing? If not, would there be utility in an `Indexes(i)` function? Perhaps also a `Gets(i; fallback)` that allows for the behavior of `get()` to be extended similarly?

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 29, 2026, 11:58pm UTC](https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531/2 "2026-07-29T23:58:47Z")

</div>

> [@brainandforce](#):
>
> `map(d -> d[:a], dicts)`

`getindex.(dicts, :a)` almost does the same job, and repeated evaluations of the expression also reuses its compiled code. But a dedicated functor would work in more higher-order functions, and I haven’t heard of a public API. Maybe someone else has.

---

<div class="post-metadata">

**Author:** ![adienes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adienes/32/37459_2.png) [@adienes](https://discourse.julialang.org/u/adienes)\
**Post date:** [July 30, 2026, 1:00am UTC](https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531/3 "2026-07-30T01:00:22Z")

</div>

there is `Iterators.nth` in 1.13

---

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [July 30, 2026, 2:09pm UTC](https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531/4 "2026-07-30T14:09:37Z")

</div>

There is `Fix2(getindex, 123)`.

---

<div class="post-metadata">

**Author:** ![abraemer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abraemer/32/51403_2.png) [@abraemer](https://discourse.julialang.org/u/abraemer)\
**Post date:** [July 30, 2026, 5:36pm UTC](https://discourse.julialang.org/t/predicate-function-for-indexing-at-a-particular-place/138531/5 "2026-07-30T17:36:34Z")

</div>

Perhaps Accessors.jl is useful to you as well

> **[Lenses · Accessors.jl](https://juliaobjects.github.io/Accessors.jl/stable/lenses/)**
