-
-
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
Add one
for AbstractString
#19548
Add one
for AbstractString
#19548
Conversation
From discussion in JuliaLang#19536
Could you add a test for the new method? |
@@ -108,6 +108,8 @@ julia> "Hello " * "world" | |||
(.*){T<:AbstractString}(v::Vector{T},s::AbstractString) = [i*s for i in v] | |||
(.*){T<:AbstractString}(s::AbstractString,v::Vector{T}) = [s*i for i in v] | |||
|
|||
one(s::AbstractString) = "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better: one{T <: AbstractString}(s::T) = convert(T, "")
Does adding a |
I don't think you need to document the new method at all, since it matches the general docstring about |
@@ -108,6 +108,8 @@ julia> "Hello " * "world" | |||
(.*){T<:AbstractString}(v::Vector{T},s::AbstractString) = [i*s for i in v] | |||
(.*){T<:AbstractString}(s::AbstractString,v::Vector{T}) = [s*i for i in v] | |||
|
|||
one{U<:AbstractString}(::Type{U}) = convert(U, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being a pain, but why use U
when the rest of the file uses T
?
Still needs a test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I did it! I contributed to open source =D |
Beware, once you start it's hard to stop... |
Thanks for the contribution @bdeonovic, but I still think this is a pun and more likely to obscure a bug in code that shouldn't be receiving strings than actually be useful for concatenation. Instead of prod, concatenating an array of strings would be better done as |
@tkelman I agree, personally I didn't want to include |
A recent issue about using sparse matrices with strings suggests that we should probably have |
@@ -108,6 +108,8 @@ julia> "Hello " * "world" | |||
(.*){T<:AbstractString}(v::Vector{T},s::AbstractString) = [i*s for i in v] | |||
(.*){T<:AbstractString}(s::AbstractString,v::Vector{T}) = [s*i for i in v] | |||
|
|||
one{T<:AbstractString}(::Type{T}) = convert(T, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency, it should probably be:
one{T<:AbstractString}(::Union{T,Type{T}}) = convert(T, "")
in analogy with e.g. one(17) == 1
.
+1. As long as |
On the one hand I agree with this. On the other I share |
We added the |
Bump! Will this make it into 0.6? |
Yes, I think the consensus was clearly for this as long as |
From discussion in #19536