-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement String(::Base.Generator) #57072
Comments
Perhaps a method that consumes general iterators would be worthwhile, e.g. 🍝(x, ::Union{HasLength,HasShape}) = String(copyto!(StringMemory(length(x)), x))
🍝(x, ::IsInfinite) = throw(MethodError(String, (x,)))
function 🍝(x, ::SizeUnknown)
io = IOBuffer()
for c in x
print(io, convert(AbstractChar, c))
end
return String(take!(io))
end
String(itr) = 🍝(itr, IteratorSize(itr)) That would allow supporting things like |
Attention: |
Maybe String(itr) = 🍝(itr, IteratorSize(itr)) |
The |
@ararslan you may want to look at the following output to see what I mean:
|
Ahhh yeah, thanks for the example, I see now. String(itr) = String([convert(AbstractChar, c) for c in itr]) should ensure you don't get a stack overflow on |
could something like this work? shows method error on String(19), works for all other cases provided :) |
I was hoping that this would work:
Instead it's a method error. We should allow the
String
constructor to take a generator argument.The text was updated successfully, but these errors were encountered: