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

Add Ref-like broadcast #22

Merged
merged 2 commits into from
Jul 31, 2024
Merged

Add Ref-like broadcast #22

merged 2 commits into from
Jul 31, 2024

Conversation

serenity4
Copy link
Contributor

@serenity4 serenity4 commented Feb 27, 2021

Currently, broadcasting over e.g. a Vector{<:Result} complains about Base.length(::Result) not defined, as Result is assumed to be an iterator type. Since Result is not an iterator, I believe it would make sense to adapt Base.broadcastable so that we can broadcast on Result containers.

I don't think this requires any tests, but I can add one if you prefer.

EDIT: my bad, broadcasting on a vector containing Results is actually fine. The problem happens when broadcasting with a Result not Refed. I still believe this to be nice to have, though.

@0x0f0f0f
Copy link
Collaborator

@serenity4 long time no see!

EDIT: my bad, broadcasting on a vector containing Results is actually fine. The problem happens when broadcasting with a Result not Refed. I still believe this to be nice to have, though.

Do you have an example?

@serenity4
Copy link
Contributor Author

👋

Do you have an example?

Sure:

julia> using ResultTypes

julia> x = [Result(1), Result(2)]
2-element Vector{Result{Int64, Exception}}:
 Result(1)
 Result(2)

julia> unwrap.(x)
2-element Vector{Int64}:
 1
 2
 
julia> x = Result(1)
Result(1)

julia> unwrap.(x)
ERROR: MethodError: no method matching length(::Result{Int64, Exception})
The function `length` exists, but no method is defined for this combination of argument types.

@0x0f0f0f
Copy link
Collaborator

@serenity4 nice! I'll approve if you add a test (now maintainer of the pkg)

@serenity4
Copy link
Contributor Author

Congrats! I was a bit worried that this package goes unmaintained, good to know it's not the case :)

I added the test.

@0x0f0f0f 0x0f0f0f merged commit 565268b into iamed2:master Jul 31, 2024
3 checks passed
@serenity4
Copy link
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants