Skip to content

Commit

Permalink
Fix handling of lists returning different type
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Oct 16, 2021
1 parent 811e1ea commit b1034b8
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/list.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ function Base.map(f::Base.Callable, l::Cons{T}) where T
push!(stack, head(l))
l::Cons{T} = tail(l)::Cons{T}
end
l2 = list(f(head(l))) # Note this might have a different eltype than T
# Note the new list might have a different eltype than T
first = f(head(l))
l2 = cons(first, nil(typeof(first) <: T ? T : typeof(first)))
for i in reverse(1:length(stack))
l2 = cons(f(stack[i]), l2)
end
Expand Down

0 comments on commit b1034b8

Please sign in to comment.