Skip to content

Commit f08ba8d

Browse files
committed
better error for map(f,String) where f doesn't return Char
1 parent 7203173 commit f08ba8d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

base/string.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,11 @@ lcfirst(s::String) = islower(s[1]) ? s : string(lowercase(s[1]),s[nextind(s,1):e
472472
function map(f::Function, s::String)
473473
out = memio(endof(s))
474474
for c in s
475-
write(out, f(c)::Char)
475+
c2 = f(c)
476+
if !isa(c2,Char)
477+
error("map(f,s::String) requires f to return Char. Try map(f,collect(s)) or a comprehension instead.")
478+
end
479+
write(out, c2::Char)
476480
end
477481
takebuf_string(out)
478482
end

0 commit comments

Comments
 (0)