Skip to content

Generalize f.(A) to tuples? #17411

Closed
Closed
@timholy

Description

@timholy

f.(A) is shorthand for broadcast(f, A), but also equivalent to map(f, A). Since we support map for both arrays and tuples, should we also support f.(t) for tuples? I may be missing it, but I can't find any place this has been discussed previously (e.g., #15032).

julia> abs.([2, -5])
2-element Array{Int64,1}:
 2
 5

julia> abs.((2, -5))
ERROR: invalid Array dimensions
 in Array{Union{},N}(::Tuple{Int64,Int64}) at ./boot.jl:319
 in similar(::Type{T}, ::Tuple{Int64,Int64}) at ./abstractarray.jl:407
 in broadcast_t(::Function, ::Type{Any}, ::Tuple{Int64,Int64}, ::Vararg{Tuple{Int64,Int64},N}) at ./broadcast.jl:189
 in broadcast(::Function, ::Tuple{Int64,Int64}) at ./broadcast.jl:204
 in eval(::Module, ::Any) at ./boot.jl:234
 in macro expansion at ./REPL.jl:92 [inlined]
 in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46

Metadata

Metadata

Assignees

No one assigned

    Labels

    broadcastApplying a function over a collection

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions