From 2448c5a8650cc67e9530cab5ff3247f30ff3d4ce Mon Sep 17 00:00:00 2001 From: serenity4 Date: Sat, 27 Feb 2021 21:39:43 +0100 Subject: [PATCH 1/2] Add Ref-like broadcast --- src/ResultTypes.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ResultTypes.jl b/src/ResultTypes.jl index fa7eb47..0eca2eb 100644 --- a/src/ResultTypes.jl +++ b/src/ResultTypes.jl @@ -7,6 +7,8 @@ struct Result{T, E <: Exception} error::Union{E, Nothing} end +Base.broadcastable(r::Result) = Ref(r) + """ Result(val::T, exception_type::Type{E}=Exception) -> Result{T, E} From f67205707387674c82dc8963016f53c15a5532b6 Mon Sep 17 00:00:00 2001 From: serenity4 Date: Wed, 31 Jul 2024 15:19:07 +0200 Subject: [PATCH 2/2] Add broadcasting test --- test/runtests.jl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 8309ef9..0f632d3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -17,6 +17,10 @@ struct FooError <: Exception end # on unwrapped already y = unwrap(x) @test unwrap(y) === y + + # can be broadcasted over + x = Result(4) + @test unwrap.(x) == 4 end @testset "Result with error type" begin