Skip to content

Commit 8f9fa29

Browse files
committed
add Returns for 1.6
1 parent 52cb8b6 commit 8f9fa29

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
@@ -91,3 +91,22 @@ end
9191
function rrule(cfg::RuleConfig{>:HasReverseMode}, ::typeof(_fast_broadcast!), f::F, x::AbstractArray, ys...) where {F<:Function}
9292
rrule_via_ad(cfg, broadcast, f, x, ys...)
9393
end
94+
95+
# Could get this from Compat.jl instead
96+
# https://github.com/JuliaLang/julia/pull/39794
97+
if VERSION < v"1.7.0-DEV.793"
98+
struct Returns{V} <: Function
99+
value::V
100+
Returns{V}(value) where {V} = new{V}(value)
101+
Returns(value) = new{Core.Typeof(value)}(value)
102+
end
103+
104+
(obj::Returns)(args...; kw...) = obj.value
105+
function Base.show(io::IO, obj::Returns)
106+
show(io, typeof(obj))
107+
print(io, "(")
108+
show(io, obj.value)
109+
print(io, ")")
110+
end
111+
end
112+

0 commit comments

Comments
 (0)