Skip to content
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

make splice! work when replacement is a length-1 generator #50430

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

adienes
Copy link
Contributor

@adienes adienes commented Jul 5, 2023

the contract for splice! asks for an "ordered collection." Looking at the implementation, empirically that seems to require length and iteration, and in the case of a length-1 replacement, also getindex. This PR removes that last restriction and concretely, allows replacement to be a length-1 generator.

before PR:

julia> arr = Any[1,2,3,4]
4-element Vector{Any}:
 1
 2
 3
 4

julia> splice!(arr, 2, (i for i in 'a'))
ERROR: MethodError: no method matching getindex(::Base.Generator{Char, typeof(identity)}, ::Int64)

after PR:

julia> arr = Any[1,2,3,4]
4-element Vector{Any}:
 1
 2
 3
 4

julia> splice!(arr, 2, (i for i in 'a'))
2

@vtjnash vtjnash added the status:merge me PR is reviewed. Merge when all tests are passing label Jul 6, 2023
@vtjnash vtjnash merged commit 6d44707 into JuliaLang:master Jul 6, 2023
2 checks passed
@brenhinkeller brenhinkeller added domain:collections Data structures holding multiple items, e.g. sets and removed status:merge me PR is reviewed. Merge when all tests are passing labels Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:collections Data structures holding multiple items, e.g. sets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants