Skip to content

Commit 6ecd9d2

Browse files
committed
add Returns for 1.6
1 parent b2969a5 commit 6ecd9d2

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/utils.jl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,22 @@ end
143143
function rrule(cfg::RuleConfig{>:HasReverseMode}, ::typeof(_fast_broadcast!), f::F, x::AbstractArray, ys...) where {F<:Function}
144144
rrule_via_ad(cfg, broadcast, f, x, ys...)
145145
end
146+
147+
# Could get this from Compat.jl instead
148+
# https://github.com/JuliaLang/julia/pull/39794
149+
if VERSION < v"1.7.0-DEV.793"
150+
struct Returns{V} <: Function
151+
value::V
152+
Returns{V}(value) where {V} = new{V}(value)
153+
Returns(value) = new{Core.Typeof(value)}(value)
154+
end
155+
156+
(obj::Returns)(args...; kw...) = obj.value
157+
function Base.show(io::IO, obj::Returns)
158+
show(io, typeof(obj))
159+
print(io, "(")
160+
show(io, obj.value)
161+
print(io, ")")
162+
end
163+
end
164+

0 commit comments

Comments
 (0)