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> 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> 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?