-
Notifications
You must be signed in to change notification settings - Fork 148
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
Consider making push/pushfirst/insert widen the type #732
Comments
While we are at it... I think it's worth considering to use widening semantics even for |
If we do If you've got a few concrete use cases it would be great to see them. |
|
Right thanks! I was more wondering about concrete use cases for |
Type-widening using BangBang
# Something like `Base.map` but you can specify the output array type:
mapto(f, T, xs) = mapfoldl(f, push!!, xs; init=T{Union{}}())
mapto(inv, Vector, 1:4)
mapto(inv, SVector{0}, 1:4)
# eltype changes Union{} -> Int -> Union{Missing,Int}
mapto(x -> isodd(x) ? missing : x, SVector{0}, 1:4) This is just a trivial example but I think this would be useful when doing something much more complex; e.g., defining static tables. FYI, there is a request for standard API for Other related discussions:
|
In #702 (comment) @tkf suggested that it would be helpful to have
push
promote the type. I'm opening this issue because while it's easy to implement I don't have a strong feeling for the benefits and drawbacks.The main drawback I see is that it's quite different from
push!
and might be surprising ifb = push(a, element)
givesb
with a differenteltype
froma
.But other than quibble it seems natural for functional manipulation of immutable data structures if the type is promoted. (Wrinkle: for consistency with StaticArrays constructors this would have to be promotion via
promote_type
rather than pure widening, otherwise we'll quickly get abstract types in numeric code.)If we did this, we should also make
pushfirst
andinsert
the same for consistency.The text was updated successfully, but these errors were encountered: