Skip to content

Commit a7100a3

Browse files
authored
Doc: Add examples and note convention of matching iteration
1 parent fb59643 commit a7100a3

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

base/broadcast.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,23 @@ end
423423
broadcastable(x)
424424
425425
Return either `x` or an object like `x` such that it supports `axes` and indexing.
426+
427+
If `x` supports iteration, the returned value should match [`collect(x)`](@ref).
428+
429+
# Examples
430+
```jldoctest
431+
julia> broadcastable([1,2,3]) # like `identity` since arrays already support axes and indexing
432+
3-element Array{Int64,1}:
433+
1
434+
2
435+
3
436+
437+
julia> broadcastable(Int) # Types don't support axes, indexing, or iteration but are commonly used as scalars
438+
Base.RefValue{Type{Int64}}(Int64)
439+
440+
julia> broadcastable("hello") # Strings break convention of matching iteration and act like a scalar instead
441+
Base.RefValue{String}("hello")
442+
```
426443
"""
427444
broadcastable(x::Union{Symbol,AbstractString,Function,UndefInitializer,Nothing,RoundingMode,Missing}) = Ref(x)
428445
broadcastable(x::Ptr) = Ref{Ptr}(x) # Cannot use Ref(::Ptr) until ambiguous deprecation goes through

0 commit comments

Comments
 (0)