Skip to content

Commit

Permalink
Allows the results of mapfoldr to be inferred on tuples. (#33235)
Browse files Browse the repository at this point in the history
  • Loading branch information
tpapp authored and JeffBezanson committed Oct 3, 2019
1 parent 60a60a5 commit bf8c324
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ reverse(G::Generator) = Generator(G.f, reverse(G.iter))
reverse(r::Reverse) = r.itr
reverse(x::Union{Number,AbstractChar}) = x
reverse(p::Pair) = Base.reverse(p) # copying pairs is cheap
reverse(xs::Tuple) = Base.reverse(xs) # allows inference in mapfoldr and similar

iterate(r::Reverse{<:Tuple}, i::Int = length(r.itr)) = i < 1 ? nothing : (r.itr[i], i-1)

Expand Down
2 changes: 2 additions & 0 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ using .Main.OffsetArrays

@test Base.mapfoldr(abs2, -, 2:5) == -14
@test Base.mapfoldr(abs2, -, 2:5; init=10) == -4
@test @inferred(mapfoldr(x -> x + 1, (x, y) -> (x, y...), (1, 2.0, '3');
init = ())) == (2, 3.0, '4')

@test foldr((x, y) -> ('' * x * '|' * y * ''), "λ 🐨.α") == "⟨λ|⟨ |⟨🐨|⟨.|α⟩⟩⟩⟩" # issue #31780
let x = rand(10)
Expand Down

0 comments on commit bf8c324

Please sign in to comment.