Skip to content

Commit

Permalink
HasShape()-trait corresponding to size(::Numbers) (#16444)
Browse files Browse the repository at this point in the history
  • Loading branch information
mschauer authored and JeffBezanson committed May 24, 2016
1 parent 71a478b commit 5474db0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/number.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ ndims(x::Number) = 0
ndims{T<:Number}(::Type{T}) = 0
length(x::Number) = 1
endof(x::Number) = 1
iteratorsize{T<:Number}(::Type{T}) = HasShape()

getindex(x::Number) = x
function getindex(x::Number, i::Integer)
@_inline_meta
Expand Down
3 changes: 3 additions & 0 deletions test/functional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ end
@test isequal(filter(x->(x>10), [0 1 2 3 2 1 0]), [])
@test isequal(filter((ss)->length(ss)==3, ["abcd", "efg", "hij", "klmn", "opq"]), ["efg", "hij", "opq"])

# numbers
@test size(collect(1)) == size(1)

# zip and filter iterators
# issue #4718
@test collect(filter(x->x[1], zip([true, false, true, false],"abcd"))) == [(true,'a'),(true,'c')]
Expand Down

0 comments on commit 5474db0

Please sign in to comment.