julia> a = Any[1, 2, 3.0]
3-element Vector{Any}:
1
2
3.0
julia> map(x->x, a)
3-element Vector{Real}:
1
2
3.0
Here I abused map to convert an array of Any to the narrowest type Real that all elements belong to. Is there a less hacky way to do this, while retaining the automatic detection of actual types inside the array?
My usage:
Using SplitApplyCombine.group to split vector of deals into a dictionary of vectors of deal subtypes. Then apply Value to each vector.
@> group( typeof, deals ) Value.()
But the vectors produced by group are all of the parent {deal} type. To apply the right Value method I need to convert each Vector{deal} to a Vector{deal-subtype} using:
It’s pretty simple to add identity.(...) explicitly before calling Value(...), no need to define new methods:
using DataPipes # not sure which piping package you used, here showing example with DataPipes
@p group(typeof, deals) |> map(Value(identity.(_)))
# or
@p group(typeof, deals) .|> Value.(identity.(__))
Being explicit helps understanding what the code actually does.
That doesn’t use the argument at all, and returns the function instead of the modified vector.
identity is definitely the wrong function to overload: it’s specifically to always return its argument unmodified.
And defining a new function, making everyone aware of it – sounds way too much simply to avoid writing the dot ..