Skip to content

Commit b1034b8

Browse files
committed
Fix handling of lists returning different type
1 parent 811e1ea commit b1034b8

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/list.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ function Base.map(f::Base.Callable, l::Cons{T}) where T
7979
push!(stack, head(l))
8080
l::Cons{T} = tail(l)::Cons{T}
8181
end
82-
l2 = list(f(head(l))) # Note this might have a different eltype than T
82+
# Note the new list might have a different eltype than T
83+
first = f(head(l))
84+
l2 = cons(first, nil(typeof(first) <: T ? T : typeof(first)))
8385
for i in reverse(1:length(stack))
8486
l2 = cons(f(stack[i]), l2)
8587
end

0 commit comments

Comments
 (0)