diff --git a/base/operators.jl b/base/operators.jl index ebd1d515f92b00..5eaaf33597aef6 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -1248,6 +1248,12 @@ used to implement specialized methods. """ <(x) = Fix2(<, x) +struct Splat{F} <: Function + f::F +end +(s::Splat)(args) = s.f(args...) +string(s::Splat) = string("splat(", s.f, ')') + """ splat(f) @@ -1269,7 +1275,7 @@ julia> map(Base.splat(+), zip(1:3,4:6)) 9 ``` """ -splat(f) = args->f(args...) +splat(f) = Splat(f) ## in and related operators diff --git a/base/show.jl b/base/show.jl index 485f9f8cc9f87f..0e3b9a364314df 100644 --- a/base/show.jl +++ b/base/show.jl @@ -46,6 +46,11 @@ end show(io::IO, ::MIME"text/plain", c::ComposedFunction) = show(io, c) show(io::IO, ::MIME"text/plain", c::Returns) = show(io, c) +function show(io::IO, ::MIME"text/plain", s::Splat) + print(io, "splat(") + show(io, s.f) + print(io, ')') +end function show(io::IO, ::MIME"text/plain", iter::Union{KeySet,ValueIterator}) isempty(iter) && get(io, :compact, false) && return show(io, iter)